Skip to content

fix: don't rebase branches whose merge commits a rebase would flatten - #22

Merged
pablospe merged 1 commit into
mainfrom
fix/skip-merge-commits
Nov 15, 2026
Merged

pablospe merged 1 commit into
mainfrom
fix/skip-merge-commits

Conversation

@pablospe

Copy link
Copy Markdown
Owner

diffnav had a local integration branch, all-features: copy-line plus merges of hunk-nav, watch-pos and clipboard-error, with hand-resolved conflicts. wt sync planned to rebase it onto copy-line. A plain git rebase drops merge commits and replays everything they brought in one commit at a time, so it would hit the same conflicts again and leave the worktree mid-rebase, which destroys a branch like that. The conflict check from #20 doesn't help here: the end result merges fine, and the trouble is in the replay.

Before a rebase, rev-list --merges --parents base..branch lists the merges it would replay. A merge counts if any merged-in side isn't already in the new parent; then the branch is skipped with everything above it, same as a predicted conflict:

Skipping all-features: it has 3 merge commits, which a rebase would flatten. Rebase it by hand (`git rebase --rebase-merges copy-line` in its worktree), then run wt sync.

A merge whose other side is already in the parent, like merging main into a feature branch to catch up, doesn't count: the rebase drops those commits as already upstream and loses nothing, so those branches are rebased as before.

The dry run plans each branch against its parent's current tip, so a branch above a parent that's about to be rebased showed as "up to date" even though the real run rebases it. For those, the plan now checks merges too, so the skip shows up in -n.

Tests in tests/conflict.rs: an integration branch on a that merges sibling b is skipped and left as is while a and b are rebased, and a feature branch that merged main into itself still gets rebased.

@pablospe
pablospe merged commit eceb22d into main Nov 15, 2026
2 checks passed
@pablospe
pablospe deleted the fix/skip-merge-commits branch November 15, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant