1GIT-RERERE(1) Git Manual GIT-RERERE(1)
2
3
4
6 git-rerere - Reuse recorded resolution of conflicted merges
7
9 git rerere [clear|forget <pathspec>|diff|remaining|status|gc]
10
11
13 In a workflow employing relatively long lived topic branches, the
14 developer sometimes needs to resolve the same conflicts over and over
15 again until the topic branches are done (either merged to the "release"
16 branch, or sent out and accepted upstream).
17
18 This command assists the developer in this process by recording
19 conflicted automerge results and corresponding hand resolve results on
20 the initial manual merge, and applying previously recorded hand
21 resolutions to their corresponding automerge results.
22
23 Note
24 You need to set the configuration variable rerere.enabled in order
25 to enable this command.
26
28 Normally, git rerere is run without arguments or user-intervention.
29 However, it has several commands that allow it to interact with its
30 working state.
31
32 clear
33 Reset the metadata used by rerere if a merge resolution is to be
34 aborted. Calling git am [--skip|--abort] or git rebase
35 [--skip|--abort] will automatically invoke this command.
36
37 forget <pathspec>
38 Reset the conflict resolutions which rerere has recorded for the
39 current conflict in <pathspec>.
40
41 diff
42 Display diffs for the current state of the resolution. It is useful
43 for tracking what has changed while the user is resolving
44 conflicts. Additional arguments are passed directly to the system
45 diff command installed in PATH.
46
47 status
48 Print paths with conflicts whose merge resolution rerere will
49 record.
50
51 remaining
52 Print paths with conflicts that have not been autoresolved by
53 rerere. This includes paths whose resolutions cannot be tracked by
54 rerere, such as conflicting submodules.
55
56 gc
57 Prune records of conflicted merges that occurred a long time ago.
58 By default, unresolved conflicts older than 15 days and resolved
59 conflicts older than 60 days are pruned. These defaults are
60 controlled via the gc.rerereUnresolved and gc.rerereResolved
61 configuration variables respectively.
62
64 When your topic branch modifies an overlapping area that your master
65 branch (or upstream) touched since your topic branch forked from it,
66 you may want to test it with the latest master, even before your topic
67 branch is ready to be pushed upstream:
68
69 o---*---o topic
70 /
71 o---o---o---*---o---o master
72
73
74 For such a test, you need to merge master and topic somehow. One way to
75 do it is to pull master into the topic branch:
76
77 $ git switch topic
78 $ git merge master
79
80 o---*---o---+ topic
81 / /
82 o---o---o---*---o---o master
83
84
85 The commits marked with * touch the same area in the same file; you
86 need to resolve the conflicts when creating the commit marked with +.
87 Then you can test the result to make sure your work-in-progress still
88 works with what is in the latest master.
89
90 After this test merge, there are two ways to continue your work on the
91 topic. The easiest is to build on top of the test merge commit +, and
92 when your work in the topic branch is finally ready, pull the topic
93 branch into master, and/or ask the upstream to pull from you. By that
94 time, however, the master or the upstream might have been advanced
95 since the test merge +, in which case the final commit graph would look
96 like this:
97
98 $ git switch topic
99 $ git merge master
100 $ ... work on both topic and master branches
101 $ git switch master
102 $ git merge topic
103
104 o---*---o---+---o---o topic
105 / / \
106 o---o---o---*---o---o---o---o---+ master
107
108
109 When your topic branch is long-lived, however, your topic branch would
110 end up having many such "Merge from master" commits on it, which would
111 unnecessarily clutter the development history. Readers of the Linux
112 kernel mailing list may remember that Linus complained about such too
113 frequent test merges when a subsystem maintainer asked to pull from a
114 branch full of "useless merges".
115
116 As an alternative, to keep the topic branch clean of test merges, you
117 could blow away the test merge, and keep building on top of the tip
118 before the test merge:
119
120 $ git switch topic
121 $ git merge master
122 $ git reset --hard HEAD^ ;# rewind the test merge
123 $ ... work on both topic and master branches
124 $ git switch master
125 $ git merge topic
126
127 o---*---o-------o---o topic
128 / \
129 o---o---o---*---o---o---o---o---+ master
130
131
132 This would leave only one merge commit when your topic branch is
133 finally ready and merged into the master branch. This merge would
134 require you to resolve the conflict, introduced by the commits marked
135 with *. However, this conflict is often the same conflict you resolved
136 when you created the test merge you blew away. git rerere helps you
137 resolve this final conflicted merge using the information from your
138 earlier hand resolve.
139
140 Running the git rerere command immediately after a conflicted automerge
141 records the conflicted working tree files, with the usual conflict
142 markers <<<<<<<, =======, and >>>>>>> in them. Later, after you are
143 done resolving the conflicts, running git rerere again will record the
144 resolved state of these files. Suppose you did this when you created
145 the test merge of master into the topic branch.
146
147 Next time, after seeing the same conflicted automerge, running git
148 rerere will perform a three-way merge between the earlier conflicted
149 automerge, the earlier manual resolution, and the current conflicted
150 automerge. If this three-way merge resolves cleanly, the result is
151 written out to your working tree file, so you do not have to manually
152 resolve it. Note that git rerere leaves the index file alone, so you
153 still need to do the final sanity checks with git diff (or git diff -c)
154 and git add when you are satisfied.
155
156 As a convenience measure, git merge automatically invokes git rerere
157 upon exiting with a failed automerge and git rerere records the hand
158 resolve when it is a new conflict, or reuses the earlier hand resolve
159 when it is not. git commit also invokes git rerere when committing a
160 merge result. What this means is that you do not have to do anything
161 special yourself (besides enabling the rerere.enabled config variable).
162
163 In our example, when you do the test merge, the manual resolution is
164 recorded, and it will be reused when you do the actual merge later with
165 the updated master and topic branch, as long as the recorded resolution
166 is still applicable.
167
168 The information git rerere records is also used when running git
169 rebase. After blowing away the test merge and continuing development on
170 the topic branch:
171
172 o---*---o-------o---o topic
173 /
174 o---o---o---*---o---o---o---o master
175
176 $ git rebase master topic
177
178 o---*---o-------o---o topic
179 /
180 o---o---o---*---o---o---o---o master
181
182
183 you could run git rebase master topic, to bring yourself up to date
184 before your topic is ready to be sent upstream. This would result in
185 falling back to a three-way merge, and it would conflict the same way
186 as the test merge you resolved earlier. git rerere will be run by git
187 rebase to help you resolve this conflict.
188
189 [NOTE] git rerere relies on the conflict markers in the file to detect
190 the conflict. If the file already contains lines that look the same as
191 lines with conflict markers, git rerere may fail to record a conflict
192 resolution. To work around this, the conflict-marker-size setting in
193 gitattributes(5) can be used.
194
196 Part of the git(1) suite
197
198
199
200Git 2.24.1 12/10/2019 GIT-RERERE(1)