18

Is it possible to change commit messages using git rebase, but without having to re-resolve merge conflicts?

I need to bowdlerize an older repo and I don't want to change any of the actual code, just the messages.

I've tried --preserve-merges.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
chpatrick
  • 461
  • 6
  • 14

2 Answers2

20

There's a little-known feature of git called "Reuse Recorded Resolutions", or rerere.

You can enable it globally by running git config --global rerere.enabled true.

If rerere is enabled, git will automatically save conflict resolutions, and will reuse those resolutions later if it encounters the same conflicts. This has the net result of not requiring the user to re-resolve these previously seen conflicts.

The feature is explained here - Git - Rerere.

The documentation for git rerere command is here - git-rerere(1).

Victor Yarema
  • 1,183
  • 13
  • 15
Jordan Lewis
  • 16,900
  • 4
  • 29
  • 46
  • 7
    Unfortunately this will only help you if you had it enabled when you first did the merges - by now it's too late. There is [a script called rerere-train](https://github.com/gitster/git/blob/master/contrib/rerere-train.sh) in the contrib portion of Git's source which goes through existing history and makes rerere learn conflict resolutions from existing merges - assuming it works, that'd help you in this case. – Cascabel Feb 13 '12 at 04:33
12

Note: since The contrib/rerere-train.sh script is supposed to re-train rerere (you can see a manual retraining here)

To make sure rerere forgets all its current rebase resolution, you now have an official option with Git 2.14.x/2.15 (Q3 2017) for contrib/rerere-train: the --overwrite flag.

See commit ad53bf7 (26 Jul 2017) by Raman Gupta (rocketraman).
(Merged by Junio C Hamano -- gitster -- in commit aec68c3, 11 Aug 2017)

contrib/rerere-train: optionally overwrite existing resolutions

Provide the user an option to overwrite existing resolutions using an --overwrite flag.

This might be used, for example, if the user knows that they already have an entry in their rerere cache for a conflict, but wish to drop it and retrain based on the merge commit(s) passed to the rerere-train script.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • How do we call rerere-train? Should we create a new file and then run the scripts? – otong Aug 31 '20 at 08:02
  • 1
    @omg you can can see example of calling [that script](https://github.com/git/git/blob/master/contrib/rerere-train.sh) in https://stackoverflow.com/a/42416725/6309 – VonC Aug 31 '20 at 08:07
  • Does this work for cherry-picks too? It doesn't seem like it would by looking at the linked source code (it seems to skip non-merges entirely). – Vegard Mar 09 '23 at 11:56
  • @Vegard I have not tested it but I doubt it would work for cherry-picking indeed. – VonC Mar 09 '23 at 12:03