DEV Community

Louis Liu
Louis Liu

Posted on

Git Deep Dive: Mastering rerere

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
Enter fullscreen mode Exit fullscreen mode

Per project:

git config rerere.enabled true
Enter fullscreen mode Exit fullscreen mode

Check status:

git config --get rerere.enabled
Enter fullscreen mode Exit fullscreen mode

Example

I'm updating hello.txt on main and feature/earth branch.

Hello!
Enter fullscreen mode Exit fullscreen mode

On main branch:

Hello World!
Enter fullscreen mode Exit fullscreen mode

On feature/earth branch:

Hello Earth!
Enter fullscreen mode Exit fullscreen mode

Now, if we try to merge feature/earth into main, we’ll get a conflict:

git checkout main
git merge feature/earth
Enter fullscreen mode Exit fullscreen mode

Conflict:

<<<<<<< HEAD
Hello World!
=======
Hello Earth!
>>>>>>> feature/earth
Enter fullscreen mode Exit fullscreen mode

We edit the file to:

Hello Universe!
Enter fullscreen mode Exit fullscreen mode

Then stage and commit:

git add hello.txt
git commit
Enter fullscreen mode Exit fullscreen mode

Git will record the resolution:

Recorded resolution for 'hello.txt'.
[main 7fd7eda] Merge branch 'feature/earth'
Enter fullscreen mode Exit fullscreen mode

Next time Git encounters the same conflict, it will automatically reuse the previous resolution:

git merge feature/earth
Enter fullscreen mode Exit fullscreen mode

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.
Enter fullscreen mode Exit fullscreen mode

Useful commands

# Manually trigger rerere
git rerere
Enter fullscreen mode Exit fullscreen mode
# Forget a recored resolution
git rerere forget <file>
Enter fullscreen mode Exit fullscreen mode
# Check the rerere cache
ls .git/rr-cache/
cat .git/rr-cache/<conflict-id>/preimage
Enter fullscreen mode Exit fullscreen mode

If you don’t want Git to auto-resolve using rerere, you can reset the file:

git checkout --conflict=merge <file>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Important Notes

  • The conflict-id is 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)