Sub topic 11
Expiry and cleanup of recorded resolutions
This chapter assumes you have rerere enabled and have recorded at least one resolution. It also assumes you know that recorded entries live in .git/rr-cache. Here you will learn how Git removes old entries on its own, how to tune that, and how to clear state by hand.
Why records need cleanup
Every conflict rerere sees creates a directory under .git/rr-cache. Each directory is named by a hash of the conflict. Most conflicts never repeat. If you abandon a branch, its records stay in the cache and are never used again. Without cleanup, the cache would grow without limit.
Git handles this during garbage collection. Running git gc, or any command that triggers it automatically, prunes old rerere entries.
How expiry works
Git treats two kinds of records differently:
- A resolved record has both a preimage (the conflicted file) and a postimage (your resolution). It is useful, so Git keeps it for a long time.
- An unresolved record has only a preimage. You never finished resolving that conflict, or you aborted it. It is less useful, so Git drops it sooner.
Age is measured from the last time the record was used or created, not from when it was first made. A resolution you reuse regularly stays fresh.
Two settings control the limits. Both are measured in days.
| Setting | Default | Applies to |
|---|---|---|
| `gc.rerereResolved` | 60 | Records with a postimage |
| `gc.rerereUnresolved` | 15 | Records with only a preimage |
You can change them like any other Git setting:
# Keep resolved records for about three months
git config gc.rerereResolved 90
# Drop unfinished records after a week
git config gc.rerereUnresolved 7
# Run garbage collection now to apply the limits
git gcSetting gc.rerereResolved higher makes sense for long-lived branches that you merge again after a long gap. If a resolution expires before the next merge, you must resolve that conflict by hand again.
placeholderClearing state with git rerere clear
git rerere clear is different from expiry. It removes the rerere state for the merge you are in the middle of. It does not touch finished records that are already stored for reuse.
Use it when you decide to abandon a merge. Suppose you started a merge, rerere recorded preimages, and then you ran git merge --abort. Git normally cleans up after an abort, but if you reset the merge by other means, stale in-progress state can remain. Clearing it avoids confusion in later git rerere status output.
git merge --abort
git rerere clear
git rerere status # should print nothingDeleting a single record by hand
If you need to remove one specific record, git rerere forget <path> is the safe route, as the previous chapter showed. You can also delete a directory from .git/rr-cache directly:
ls .git/rr-cache
rm -r .git/rr-cache/<hash-directory>Deleting the whole rr-cache directory is also safe. Git recreates it when it records the next conflict. You lose only your saved resolutions.
Common mistakes
- Expecting
git rerere clearto wipe the whole cache. It only clears the current in-progress state. - Setting the limits and never running
git gc. Expiry happens only when garbage collection runs. Automatic gc runs occasionally, but not on a schedule you control. - Setting
gc.rerereResolvedto a very low value on a long-lived branch. The resolution may expire before you need it.
Exercise
You resolved a conflict on a release branch in January. You expect to merge the same branch again in June, about 150 days later. With default settings, what can happen to the recorded resolution, and what setting would you change?
Show answer
With the default gc.rerereResolved of 60 days, a git gc run in the gap would delete the unused record, so you would have to resolve the conflict by hand again. Raise it, for example with git config gc.rerereResolved 200, so the record survives until June. Reusing the record also refreshes its age.
Exercise
What is the difference between git rerere clear and git gc as far as rerere is concerned?
Show answer
git rerere clear removes the in-progress rerere state of the current merge, such as preimages for conflicts you have not finished. git gc expires stored records by age, using gc.rerereResolved for resolved records and gc.rerereUnresolved for unresolved ones.