Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Merging and Rebasing

git rerere command

Reference for git rerere: record how you resolved a merge conflict and replay it automatically, with rerere.enabled, status, diff, forget, clear and gc.

rerere stands for reuse recorded resolution. When it is enabled, Git remembers the conflict you faced and the way you resolved it. The next time the very same conflict appears, Git applies your old resolution on its own and tells you so. You still review and git add the file; rerere just removes the repetition.

It pays off in three situations: re-doing a merge after throwing it away, rebasing a long-lived branch again and again, and keeping a long-running integration branch in sync with several topic branches. Nothing happens unless you switch it on with git config rerere.enabled true.

Terminal
git config rerere.enabled true
git merge topic        # conflict: Recorded preimage for 'file'
# resolve, add, commit: Recorded resolution for 'file'
git reset --hard HEAD~ && git merge topic   # Resolved 'file' using previous resolution.

Try it

Bash Resolve once, replay automatically

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Inspecting, forgetting and clearing

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git rerere [clear | forget <pathspec>... | diff | status | remaining | gc]
git config rerere.enabled true
Subcommand Description
(none) Record or replay resolutions for the current conflicted files. Commands such as merge and rebase call this for you.
status List paths whose conflicts rerere is tracking in the current merge.
remaining List paths still unresolved, including conflicts rerere has not solved.
diff Show the current state of the resolution compared to the recorded conflict.
forget <pathspec> Discard the saved resolution for this path's conflict, so you can resolve it again.
clear Reset the in-progress conflict records. Only valid during a merge; saved resolutions stay.
gc Prune old records: unresolved conflicts after 15 days, resolved ones after 60 (gc.rerereUnresolved, gc.rerereResolved).
Configuration Meaning
rerere.enabled Turn rerere on. If unset, it is also on when .git/rr-cache exists.
rerere.autoUpdate Stage files that rerere resolved. Default false, so you can check them.

Messages: Recorded preimage for 'f' (conflict snapshot saved), Recorded resolution for 'f' (your fix saved), Resolved 'f' using previous resolution. (replayed).

Usage notes

  • Identical conflicts only. Git matches the conflicted text, with the order of the two sides normalized. Change a nearby line so the hunk differs and the old answer does not apply.
  • Replay does not stage. The file is rewritten without markers, yet git status still shows it as unmerged. Check it, then git add. Set rerere.autoUpdate true to skip that step.
  • Per repository. The cache is .git/rr-cache/<hash>/ (a preimage and a postimage). It is not part of history and is not pushed. Share it by copying that folder if a team needs the same answers.
  • Wrong answer saved? Use git rerere forget <path> right after the bad merge, while the conflict is still unresolved, then resolve again.
  • Great with rebase. If you rebase a topic branch repeatedly while main moves, the same conflict reappears in each rebase; rerere solves it silently after the first time. See git rebase.
  • Test merges. Merge, resolve, record, then git reset --hard and keep going. The resolution is reused when you merge for real.
  • Safe by design. Rerere only touches files in the working tree during an operation that already left conflict markers, so it never rewrites history.
  • It is only a cache. If the cache is lost you simply resolve the conflict by hand again.