Sub topic 7
Looking at what rerere is tracking
This chapter assumes you have rerere enabled, as shown earlier, and that you have recorded and reused at least one resolution. You should also be comfortable reading conflict markers and running Git in a terminal.
rerere works silently. A conflict is recorded when it first appears, and a resolution is saved when you commit. A few read-only commands let you see this state, which helps when a merge behaves differently than you expected.
Four ways to look
All four commands below are safe to run at any time. They change nothing.
git rerere status # files rerere is tracking in the current conflict
git rerere diff # current state of the resolution compared with the recorded conflict
git rerere remaining # files that still have unresolved conflicts, including ones rerere has not resolved
ls .git/rr-cache/* # one directory per recorded conflict, with preimage and postimage filesThe first three only report on the merge, rebase, or cherry-pick that is in progress. The fourth shows what rerere has stored over time.
status: what rerere is tracking
git rerere status prints one path per line for each file whose conflict rerere has noted in the current operation. Run it right after a conflicting merge:
git merge feature
git rerere statussettings.txtA file appears here whether rerere reused an old resolution or only recorded a new conflict. It tells you what rerere watches, not what it has solved.
remaining: what is still yours to fix
git rerere remaining lists the paths that rerere has not resolved automatically. After a first-time conflict, settings.txt appears in this list. After a repeat of the same conflict, where rerere reused a resolution, the list is empty. The file is not staged by default, so git status still shows it as unmerged.
The command also lists paths that rerere cannot track at all, such as conflicting submodules. A path that appears in remaining but not in status is a sign that rerere cannot help with it.
diff: what your edit changed
git rerere diff compares the recorded conflict (the preimage) with the file as it is now. Use it while you resolve a conflict. Before you edit, the diff is empty or small. After you edit, it shows what you did to the conflicted region.
For the earlier demo, after you replace the markers with color=teal, the diff looks roughly like this:
-<<<<<<<
-color=blue
-=======
-color=green
->>>>>>>
+color=tealThe marker lines have no branch names because rerere stores a normalized form of the conflict. This is the change that rerere will save as the postimage when you stage the file.
The command passes extra arguments to the system diff. For example, git rerere diff -u is accepted. This is useful when a conflicted hunk is long.
The cache directory
Each directory under .git/rr-cache/ is named by a hash that identifies one conflict. Look inside one:
ls .git/rr-cache/*.git/rr-cache/3b1f.../postimage
.git/rr-cache/3b1f.../preimageThe hash will differ on your machine. The contents tell you the state of that conflict:
| Files in the directory | Meaning |
|---|---|
| `preimage` only | The conflict was seen, but no resolution has been recorded yet. |
| `preimage` and `postimage` | A resolution was recorded and can be reused. |
A directory with only a preimage is normal. It means you saw a conflict and have not yet committed a resolution. It can also mean you aborted the merge, so no resolution exists to reuse.
A short checking routine
When a repeated merge does not behave as you expect, work through these steps:
- Run
git rerere status. If your file is missing, rerere did not notice that conflict. Check thatrerere.enabledis set. - Run
git rerere remaining. If the file is listed, rerere found no matching recorded resolution. - Run
ls .git/rr-cache/*. If no directory has apostimage, nothing has been recorded yet.
Exercise
You merge a branch and git rerere status lists settings.txt, but git rerere remaining prints nothing. What does that tell you, and what must you still do?
Show answer
rerere tracked the conflict in settings.txt and resolved it using a recorded resolution, so no conflicts remain for you to fix by hand. You must still review the file, stage it with git add (unless rerere.autoupdate is on), and commit the merge.