Reuse conflict resolutions with git rerere
Enable git rerere to reuse a conflict resolution the next time Git recognizes the same conflict.
You rebase feature onto main, fix a conflict in settings.txt, and then have to rebase again. The same conflict is back, and you fix it a second time. Git can remember the first fix.
diagram
A conflict resolved once and replayed by rerere
Turn rerere on and resolve once
git rerere uses rerere.enabled. With that setting unset, Git enables rerere only if its cache directory already exists. In my sandbox repo, main set timeout=60 and feature set timeout=45 on the same line.
$ git config rerere.enabled true
$ git branch before-rebase
$ git rebase main
CONFLICT (content): Merge conflict in settings.txt
Recorded preimage for 'settings.txt'
$ cat settings.txt
host=localhost
<<<<<<< HEAD
timeout=60
=======
timeout=45
>>>>>>> a4d5ab6 (feature: timeout 45)Git stopped on the conflict, as usual, and printed Recorded preimage, the first half of the record. I kept the feature's value, saved the file without markers, and continued.
$ git add settings.txt
$ git rebase --continue
Recorded resolution for 'settings.txt'.
Successfully rebased and updated refs/heads/feature.The Recorded resolution line means git stored my edited file next to the preimage, under .git/rr-cache/<hash>/ as preimage and postimage.
Rebase again and watch it replay
To reproduce the conflict in a scratch repo, reset feature to the branch you saved before the rebase. A hard reset discards tracked edits, so check git status first.
$ git reset --hard before-rebase
$ git rebase main
CONFLICT (content): Merge conflict in settings.txt
Resolved 'settings.txt' using previous resolution.
$ cat settings.txt
host=localhost
timeout=45
$ git status --short
UU settings.txtThe file holds the earlier resolution. With rerere.autoupdate off, Git leaves the index unmerged until you review and stage the file. I ran git add settings.txt and git rebase --continue, and it finished with the same two commits.
When it replays
Rerere replays only a conflict it has seen. In another run I amended the feature commit to timeout=46 between the first and second rebase. Git printed Recorded preimage again and left the markers for me, because the two sides no longer matched.
A merge records the same way. In a separate run, git commit after a merge conflict printed Recorded resolution, and the second merge printed Resolved 'settings.txt' using previous resolution.
Read the replayed file before you git add it. Git filled it from a record, and you are the one who decides whether that answer still fits the code around it.