Sub topic 8
Letting rerere stage the result: rerere.autoupdate
This chapter assumes you have rerere enabled and have already recorded at least one resolution, as in the walkthrough chapter. You should know the difference between the working tree and the index (the staging area), and what git add does to a conflicted file.
What rerere leaves undone by default
When rerere reuses a recorded resolution, it rewrites the conflicted file in your working tree. By default it stops there. The file is still listed as unmerged, and the index still holds the three conflict stages. You must run git add yourself, just as you would after a manual fix.
That pause is intentional. It gives you a moment to check that the old resolution still makes sense in the new context. Setting rerere.autoupdate removes the pause by staging the reused result for you.
Turning it on
# For every repository of the current user
git config --global rerere.autoupdate true
# Or only for the current repository
git config rerere.autoupdate trueYou can also decide per command. The flag --rerere-autoupdate works on commands that can hit conflicts, such as merge, rebase, cherry-pick, revert and am. --no-rerere-autoupdate turns the behavior off for one command even when the config enables it.
Seeing the difference
This example continues from the rerere-demo repository built in the walkthrough chapter. The resolution color=teal is already recorded.
cd rerere-demo
# Undo the merge commit made at the end of the walkthrough
git reset --hard HEAD^
# Repeat the merge, asking rerere to stage what it resolves
git merge --rerere-autoupdate feature
# Resolved 'settings.txt' using previous resolution.
# Staged 'settings.txt' using previous resolution.
# Automatic merge failed; fix conflicts and then commit the result.
git status --short # "M settings.txt": staged, no longer "UU"
git diff --cached # review exactly what was staged
git commit --no-editCompare this with the walkthrough, where the same merge left settings.txt marked UU until you ran git add. With autoupdate, Git prints a second line saying it staged the file, and the status shows the file as already added.
The merge itself still stops. Autoupdate only handles the staging step. You still run git commit to finish a merge, or git rebase --continue during a rebase.
When to enable it
Autoupdate fits workflows where the same conflicts recur many times and you trust the recorded answers. An example is a throwaway integration branch that you rebuild every day by merging a dozen topic branches. Staging by hand each time is repetitive and adds little.
It is a poorer fit when resolutions are rare or were recorded long ago. A reused resolution is only as good as the context it was recorded in. Surrounding code may have changed in ways that keep the conflict textually identical but make the old answer wrong.
Common errors
- Expecting autoupdate to resolve new conflicts. It acts only on conflicts that match a recorded resolution. Any other conflict still needs a manual fix, and
git rerere remaininglists those files. - Expecting the merge to finish by itself. The commit or
--continuestep is still yours. - Staging a bad resolution without noticing. If a reused result is wrong, recreate the conflict with
git checkout --merge -- <file>, then rungit rerere forget <file>. Resolve the file again andgit addit so the corrected version is recorded. - Forgetting the config is global. A global
rerere.autoupdate trueapplies to every repository. Override it per repository withgit config rerere.autoupdate false, or per command with--no-rerere-autoupdate.
Exercise
You have rerere.autoupdate set to true. You run git merge feature, and Git prints "Staged 'settings.txt' using previous resolution." What do you still need to do to finish the merge, and what should you check first?
Show answer
Run git commit to complete the merge, since autoupdate only stages files and does not create the commit. Before committing, run git diff --cached to confirm the staged content is what you want, because the reused resolution may no longer fit the surrounding code.