The Repeated Conflict Problem
Imagine you are working on a long-lived feature branch. Every morning you rebase it against main to stay current. And every morning, the same three files conflict in the same places — because your feature and a parallel change in main both touch the same configuration block. You resolve them, rebase succeeds, and the next morning you do it all over again.
git rerere stands for "REuse REcorded REsolution". It is Git's memory for conflict resolutions.
How It Works
Enabled once, globally, Git maintains a cache in .git/rr-cache/. The workflow is:
- You attempt a merge or rebase and hit a conflict.
- Git records the pre-image: the exact state of the conflict markers in the file.
- You manually resolve the conflict and stage the file.
- Git records the post-image: your resolved version.
- The next time Git encounters the identical pre-image (same conflict markers, same surrounding context), it automatically applies your post-image — resolving the conflict without any input from you.
Git will print Resolved 'filename' using previous resolution. so you know rerere fired.
What "Identical" Means
Rerere matches conflicts based on the content of the conflict markers — the lines between <<<<<<<, =======, and >>>>>>>. If the conflicting content changes even slightly (e.g., a new line is added nearby), rerere will not match and you must resolve manually. This is by design: rerere only replays resolutions it is certain about.
Practical Impact
Rerere is most valuable in two scenarios:
1. Long-lived feature branches that rebase against main frequently.
2. Octopus merges or integration branches where the same topic branches are merged repeatedly during testing.
A common interview question is: "How do you handle repeated merge conflicts on a long-lived branch?" Many candidates say "rebase more often" (correct but incomplete). The complete answer includes git rerere — enable it, resolve once, and Git replays the resolution automatically. Follow-up: "What's the risk?" Answer: if the surrounding code changes enough that the old resolution is no longer semantically correct, rerere will apply a stale fix silently. Always review rerere-resolved files before committing.