1GIT-RERERE(1)                     Git Manual                     GIT-RERERE(1)
2
3
4

NAME

6       git-rerere - Reuse recorded resolution of conflicted merges
7

SYNOPSIS

9       git rerere [clear|forget <pathspec>|diff|remaining|status|gc]
10

DESCRIPTION

12       In a workflow employing relatively long lived topic branches, the
13       developer sometimes needs to resolve the same conflicts over and over
14       again until the topic branches are done (either merged to the "release"
15       branch, or sent out and accepted upstream).
16
17       This command assists the developer in this process by recording
18       conflicted automerge results and corresponding hand resolve results on
19       the initial manual merge, and applying previously recorded hand
20       resolutions to their corresponding automerge results.
21
22           Note
23           You need to set the configuration variable rerere.enabled in order
24           to enable this command.
25

COMMANDS

27       Normally, git rerere is run without arguments or user-intervention.
28       However, it has several commands that allow it to interact with its
29       working state.
30
31       clear
32           Reset the metadata used by rerere if a merge resolution is to be
33           aborted. Calling git am [--skip|--abort] or git rebase
34           [--skip|--abort] will automatically invoke this command.
35
36       forget <pathspec>
37           Reset the conflict resolutions which rerere has recorded for the
38           current conflict in <pathspec>.
39
40       diff
41           Display diffs for the current state of the resolution. It is useful
42           for tracking what has changed while the user is resolving
43           conflicts. Additional arguments are passed directly to the system
44           diff command installed in PATH.
45
46       status
47           Print paths with conflicts whose merge resolution rerere will
48           record.
49
50       remaining
51           Print paths with conflicts that have not been autoresolved by
52           rerere. This includes paths whose resolutions cannot be tracked by
53           rerere, such as conflicting submodules.
54
55       gc
56           Prune records of conflicted merges that occurred a long time ago.
57           By default, unresolved conflicts older than 15 days and resolved
58           conflicts older than 60 days are pruned. These defaults are
59           controlled via the gc.rerereUnresolved and gc.rerereResolved
60           configuration variables respectively.
61

DISCUSSION

63       When your topic branch modifies an overlapping area that your master
64       branch (or upstream) touched since your topic branch forked from it,
65       you may want to test it with the latest master, even before your topic
66       branch is ready to be pushed upstream:
67
68                         o---*---o topic
69                        /
70               o---o---o---*---o---o master
71
72       For such a test, you need to merge master and topic somehow. One way to
73       do it is to pull master into the topic branch:
74
75                   $ git switch topic
76                   $ git merge master
77
78                         o---*---o---+ topic
79                        /           /
80               o---o---o---*---o---o master
81
82       The commits marked with * touch the same area in the same file; you
83       need to resolve the conflicts when creating the commit marked with +.
84       Then you can test the result to make sure your work-in-progress still
85       works with what is in the latest master.
86
87       After this test merge, there are two ways to continue your work on the
88       topic. The easiest is to build on top of the test merge commit +, and
89       when your work in the topic branch is finally ready, pull the topic
90       branch into master, and/or ask the upstream to pull from you. By that
91       time, however, the master or the upstream might have been advanced
92       since the test merge +, in which case the final commit graph would look
93       like this:
94
95                   $ git switch topic
96                   $ git merge master
97                   $ ... work on both topic and master branches
98                   $ git switch master
99                   $ git merge topic
100
101                         o---*---o---+---o---o topic
102                        /           /         \
103               o---o---o---*---o---o---o---o---+ master
104
105       When your topic branch is long-lived, however, your topic branch would
106       end up having many such "Merge from master" commits on it, which would
107       unnecessarily clutter the development history. Readers of the Linux
108       kernel mailing list may remember that Linus complained about such too
109       frequent test merges when a subsystem maintainer asked to pull from a
110       branch full of "useless merges".
111
112       As an alternative, to keep the topic branch clean of test merges, you
113       could blow away the test merge, and keep building on top of the tip
114       before the test merge:
115
116                   $ git switch topic
117                   $ git merge master
118                   $ git reset --hard HEAD^ ;# rewind the test merge
119                   $ ... work on both topic and master branches
120                   $ git switch master
121                   $ git merge topic
122
123                         o---*---o-------o---o topic
124                        /                     \
125               o---o---o---*---o---o---o---o---+ master
126
127       This would leave only one merge commit when your topic branch is
128       finally ready and merged into the master branch. This merge would
129       require you to resolve the conflict, introduced by the commits marked
130       with *. However, this conflict is often the same conflict you resolved
131       when you created the test merge you blew away. git rerere helps you
132       resolve this final conflicted merge using the information from your
133       earlier hand resolve.
134
135       Running the git rerere command immediately after a conflicted automerge
136       records the conflicted working tree files, with the usual conflict
137       markers <<<<<<<, =======, and >>>>>>> in them. Later, after you are
138       done resolving the conflicts, running git rerere again will record the
139       resolved state of these files. Suppose you did this when you created
140       the test merge of master into the topic branch.
141
142       Next time, after seeing the same conflicted automerge, running git
143       rerere will perform a three-way merge between the earlier conflicted
144       automerge, the earlier manual resolution, and the current conflicted
145       automerge. If this three-way merge resolves cleanly, the result is
146       written out to your working tree file, so you do not have to manually
147       resolve it. Note that git rerere leaves the index file alone, so you
148       still need to do the final sanity checks with git diff (or git diff -c)
149       and git add when you are satisfied.
150
151       As a convenience measure, git merge automatically invokes git rerere
152       upon exiting with a failed automerge and git rerere records the hand
153       resolve when it is a new conflict, or reuses the earlier hand resolve
154       when it is not. git commit also invokes git rerere when committing a
155       merge result. What this means is that you do not have to do anything
156       special yourself (besides enabling the rerere.enabled config variable).
157
158       In our example, when you do the test merge, the manual resolution is
159       recorded, and it will be reused when you do the actual merge later with
160       the updated master and topic branch, as long as the recorded resolution
161       is still applicable.
162
163       The information git rerere records is also used when running git
164       rebase. After blowing away the test merge and continuing development on
165       the topic branch:
166
167                         o---*---o-------o---o topic
168                        /
169               o---o---o---*---o---o---o---o   master
170
171                   $ git rebase master topic
172
173                                             o---*---o-------o---o topic
174                                            /
175               o---o---o---*---o---o---o---o   master
176
177       you could run git rebase master topic, to bring yourself up to date
178       before your topic is ready to be sent upstream. This would result in
179       falling back to a three-way merge, and it would conflict the same way
180       as the test merge you resolved earlier. git rerere will be run by git
181       rebase to help you resolve this conflict.
182
183       [NOTE] git rerere relies on the conflict markers in the file to detect
184       the conflict. If the file already contains lines that look the same as
185       lines with conflict markers, git rerere may fail to record a conflict
186       resolution. To work around this, the conflict-marker-size setting in
187       gitattributes(5) can be used.
188

GIT

190       Part of the git(1) suite
191
192
193
194Git 2.30.2                        2021-03-08                     GIT-RERERE(1)
Impressum