TIL: git rerere Remembers Your Conflict Resolutions
git rerere, short for reuse recorded resolution, saves how you resolved each conflict and reapplies it the next time the same hunk conflicts. Enable it with git config --global rerere.enabled true.
Git can remember how you fixed a merge conflict and do the same fix again next time. The setting is git rerere, short for reuse recorded resolution. It is off by default.
git config --global rerere.enabled true
From then on, every conflict you fix and commit gets saved in .git/rr-cache. Git keeps the block of lines it could not merge and what you changed them to. The next time that same block conflicts, git puts your fix in and leaves the file for you to check. Set rerere.autoUpdate to true and it adds the fixed file to the commit for you as well.
This is most useful when you give up on a rebase halfway through. Start it again and the conflicts you already fixed get fixed for you. Same when you copy one fix onto three release branches with git cherry-pick.
The git config defaults post left this one out.
What if I recorded a bad resolution?
git rerere forget <path> deletes the saved fix for that file. git rerere diff shows you what it is about to change before you trust it.
Does it work across repos?
No. The saved fixes live in each repo’s own .git folder. Old ones get cleared out by git rerere gc, and git gc runs that for you.