No, It's Not a Typo: Let's Talk About git rerere (Reuse Recorded Resolution)
git rerere helps Git remember how you resolved a conflict previously, and automatically reuses that resolution when the same conflict occurs again. This can be a huge time-saver with recurring merge conflicts.
How to enabled it
Globally:
git config --global rerere.enabled true
Per project:
git config rerere.enabled true
Check status:
git config --get rerere.enabled
Example
I'm updating hello.txt on main and feature/earth branch.
Hello!
On main branch:
Hello World!
On feature/earth branch:
Hello Earth!
Now, if we try to merge feature/earth into main, we’ll get a conflict:
git checkout main
git merge feature/earth
Conflict:
<<<<<<< HEAD
Hello World!
=======
Hello Earth!
>>>>>>> feature/earth
We edit the file to:
Hello Universe!
Then stage and commit:
git add hello.txt
git commit
Git will record the resolution:
Recorded resolution for 'hello.txt'.
[main 7fd7eda] Merge branch 'feature/earth'
Next time Git encounters the same conflict, it will automatically reuse the previous resolution:
git merge feature/earth
You got:
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Resolved 'hello.txt' using previous resolution.
Automatic merge failed; fix conflicts and then commit the result.
Useful commands
# Manually trigger rerere
git rerere
# Forget a recored resolution
git rerere forget <file>
# Check the rerere cache
ls .git/rr-cache/
cat .git/rr-cache/<conflict-id>/preimage
If you don’t want Git to auto-resolve using rerere, you can reset the file:
git checkout --conflict=merge <file>
Advanced
When Git detects a conflict during a merge or rebase, it generates a hash key based on the conflicting content — this becomes the conflict-id.
Git then stores:
- The preimage (conflicted content)
- The postimage (your resolved version)
These are saved under .git/rr-cache/.
File Structure:
.git/
└── rr-cache/
├── <conflict-id>/
│ ├── preimage # The file before conflict resolution
│ ├── postimage # The file after conflict resolution
│ └── thisimage # Temporary file used during auto-resolution
Important Notes
- The
conflict-idis not a Git object, even though it looks like one. - It’s stored locally only — it won’t be pushed to the remote.
- If you delete
.git/rr-cache, the resolution is gone forever.
Summary
git rerere is a powerful but often overlooked tools. It can save you a lot of time when dealing with recurring merge conflicts.
Top comments (0)