chkpnt
chkpnt

Reputation: 387

How to preserve adjusted merge commits (conflicting and non-conflicting automerge results) with git rebase?

I'm using git rebase -i --rebase-merges <commit> to change some commit messages, which works fine. But the merge commits I'd like to preserve had changes or conflict solutions; is there an easy way to redo them?

My current work around is the following:

  1. in the interactive rebase overview, change merge -C <commit> to merge -c <commit> to ensure the merge commit is not automatically committed
  2. when the merge commit is up, checkout the state of the original merge: git checkout <commit> -- . (-- . is needed to prevent HEAD being resetted to )
  3. review the staging area
  4. continue the rebase

Upvotes: 0

Views: 213

Answers (1)

torek
torek

Reputation: 488193

There is no Royal Road here: when you've made an evil merge and ask Git to re-perform that merge (with git rebase -r or similar), Git simply won't make an evil merge.

For this reason, it's sometimes better to make a non-evil merge and follow it up with a fixup commit, even if the non-evil merge is "bad" in some sense (e.g., does not compile or contains a known bug). If you dislike that method, sometimes you can make a commit before making the merge, so that the resulting non-evil merge is good. But this may push the "badness" into that commit (the pre-merge fixup), leaving you with the same bad-tasting setup.

You have your pick of bad solutions: make an evil merge and avoid rebasing it; make an evil merge and put extra effort in when rebasing it; or avoid the evil merge by using fixup commits.

Upvotes: 1

Related Questions