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
.
The traditional way of completing a merge after resolving conflicts is to use ' git commit '. Now with commands like ' git rebase ' and ' git cherry-pick ' having a ' --continue ' option adding such an option to ' git merge ' presents a consistent UI.
To fix the conflict, you can follow the standard procedures for resolving merge conflicts from the command line. When you're finished, you'll need to call git rebase --continue in order for Git to continue processing the rest of the rebase.
For current Git versions (2020+), just do git rebase -i -r <parent> , then replace in the editor merge -C with merge -c . This will open the merge commit's message in the editor during rebasing, where you can change it (thanks to VonC for the hint).
The Rebase Option But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge .
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).
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 resolutionsProvide 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With