Video in progress
On a long-lived branch, every time you update from `main` you resolve the same conflicts again. How does `git rerere` help?
rerere (reuse recorded resolution) remembers how you resolved a conflict. If exactly that conflict comes up again, Git applies the earlier resolution automatically. It is especially useful with repeated rebases and trial merges.
📖 Answer
Turning it on is one line:
git config --global rerere.enabled true
How it works: a conflict appears, Git records the "fingerprint" of the conflict hunk, you resolve it and git add, and Git saves the result tied to that fingerprint (.git/rr-cache). The next time the same conflict appears:
Resolved 'src/main/java/.../TariffService.java' using previous resolution.
The file is already fixed, but it is not staged automatically (unless rerere.autoUpdate is on). You look it over, run the tests, and then git add.
Where it comes in handy:
- if you rebase a feature branch onto
mainevery day, the same commits give the same conflict every time; - a "trial merge": you merge
maininto the branch, test it, and then abort the merge. When the real merge happens, the resolution is ready; - when carrying the same change over to several release branches.
One place to be careful: it remembers a wrong resolution too. To make it forget: git rerere forget <file>.
But to be honest, rerere often only eases the symptom. The real cure is to keep branches short and to merge into main sooner behind a feature flag.
Sign up to mark studied questions and save your progress.