Sub topic 3
Turning rerere on
This chapter assumes you can commit, branch, merge, and rebase, and that you can resolve conflict markers by hand. It covers how to enable rerere and how Git decides whether it is active.
rerere is off by default
Git does not record conflict resolutions until you ask it to. A merge that conflicts leaves nothing behind except your edits, so a repeat of the same conflict starts from scratch. One setting changes this: rerere.enabled.
Choosing a scope
Git reads rerere.enabled from its normal configuration levels. You pick the level that matches how widely you want rerere active.
# Every repository of the current user
git config --global rerere.enabled true
# Only the current repository
git config rerere.enabled trueThe first command writes to ~/.gitconfig. The second writes to .git/config inside the repository. The repository value overrides the global one, so a repository can opt out of a global setting:
git config rerere.enabled falseMost people enable it globally. Recording costs almost nothing when no conflict occurs, and it only acts when a merge stops on a conflict.
Trying it for one command
You can turn rerere on for a single command without changing any configuration. The -c option sets a value for that command only:
git -c rerere.enabled=true merge featureThis is useful when you want to try rerere on one tricky merge before deciding to keep it on.
Checking what is active
Ask Git for the value and where it came from:
git config --show-origin --get rerere.enabledThe output names the file that supplied the value, followed by the value itself. If the command prints nothing, the setting is unset. Unset does not always mean off, as the next section explains.
The unset case and .git/rr-cache
When rerere.enabled is unset, Git falls back to an older rule. It enables rerere if the directory .git/rr-cache exists, and leaves it off otherwise. Creating that directory by hand used to be the way to turn the feature on. Today an explicit setting is clearer, and it takes priority over the directory. If you set rerere.enabled to false, rerere stays off even when .git/rr-cache exists.
# Unset, no directory: off
# Unset, directory exists: on
# true: on
# false: off, even if the directory existsWhich operations use it
Once enabled, rerere is not limited to git merge. It runs in any operation that can stop on a content conflict, including rebase, cherry-pick, revert, and git stash pop. You do not enable it per command. The same setting covers all of them.
What changes on your first conflict
Enabling rerere changes nothing you see until a conflict happens. On the next conflicting merge, Git prints a line like this:
Recorded preimage for 'settings.txt'That line confirms rerere is working. It has saved the conflicted version of the file. When you later resolve the file and commit, Git saves your result as well. The next chapters explain how these two saved states are stored and reused.
Related settings
Enabling rerere is one switch. Two other settings tune its behavior, and both are covered in later chapters:
| Setting | Effect |
|---|---|
| `rerere.autoupdate` | Stages files that rerere resolved automatically |
| `gc.rerereResolved`, `gc.rerereUnresolved` | Set how many days `git gc` keeps records |
Neither one is needed to start. Leave them at their defaults for now.
Exercise
You run git config --global rerere.enabled true, but one repository has rerere.enabled set to false in its .git/config. Is rerere active in that repository? How would you check which value applies?
Show answer
No. The repository-level value overrides the global one, so rerere is off there. Run git config --show-origin --get rerere.enabled inside the repository. It prints the value Git uses and the file that supplied it, which will be .git/config.
Exercise
In a repository where rerere.enabled is unset, you find that .git/rr-cache exists. Is rerere active, and what single setting would turn it off?
Show answer
Yes, because an unset rerere.enabled falls back to the presence of .git/rr-cache. Running git config rerere.enabled false turns it off, since an explicit false overrides the directory.