0

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
chkpnt
  • 125
  • 10
  • 2
    Does this answer your question? [What is git-rerere and how does it work?](https://stackoverflow.com/questions/49500943/what-is-git-rerere-and-how-does-it-work) – mkrieger1 Jul 01 '21 at 14:16
  • Uh, didn't know `git-rerere` until now! Thanks, it will for sure help me in some other situation. In my current situation, I've non-conflicting but adjusted merge commits, too. – chkpnt Jul 01 '21 at 19:22

1 Answers1

1

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.

torek
  • 448,244
  • 59
  • 642
  • 775