1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
\r
4 <article lang="en" id="git-rerere(1)">
\r
6 <title>git-rerere(1)</title>
\r
8 <primary>git-rerere(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-rerere - Reuse recorded resolution of conflicted merges</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
17 <simpara><emphasis>git rerere</emphasis> [<emphasis>clear</emphasis>|<emphasis>diff</emphasis>|<emphasis>status</emphasis>|<emphasis>gc</emphasis>]</simpara>
\r
19 <simplesect id="_description">
\r
20 <title>DESCRIPTION</title>
\r
21 <simpara>In a workflow that employs relatively long lived topic branches,
\r
22 the developer sometimes needs to resolve the same conflict over
\r
23 and over again until the topic branches are done (either merged
\r
24 to the "release" branch, or sent out and accepted upstream).</simpara>
\r
25 <simpara>This command helps this process by recording conflicted
\r
26 automerge results and corresponding hand-resolve results on the
\r
27 initial manual merge, and later by noticing the same automerge
\r
28 results and applying the previously recorded hand resolution.</simpara>
\r
29 <note><simpara>You need to set the configuration variable rerere.enabled to
\r
30 enable this command.</simpara></note>
\r
32 <simplesect id="_commands">
\r
33 <title>COMMANDS</title>
\r
34 <simpara>Normally, <emphasis>git-rerere</emphasis> is run without arguments or user-intervention.
\r
35 However, it has several commands that allow it to interact with
\r
36 its working state.</simpara>
\r
40 <emphasis>clear</emphasis>
\r
44 This resets the metadata used by rerere if a merge resolution is to be
\r
45 aborted. Calling <emphasis>git-am [--skip|--abort]</emphasis> or <emphasis>git-rebase [--skip|--abort]</emphasis>
\r
46 will automatically invoke this command.
\r
52 <emphasis>diff</emphasis>
\r
56 This displays diffs for the current state of the resolution. It is
\r
57 useful for tracking what has changed while the user is resolving
\r
58 conflicts. Additional arguments are passed directly to the system
\r
59 <emphasis>diff</emphasis> command installed in PATH.
\r
65 <emphasis>status</emphasis>
\r
69 Like <emphasis>diff</emphasis>, but this only prints the filenames that will be tracked
\r
76 <emphasis>gc</emphasis>
\r
80 This command is used to prune records of conflicted merge that
\r
81 occurred long time ago. By default, conflicts older than 15
\r
82 days that you have not recorded their resolution, and conflicts
\r
83 older than 60 days, are pruned. These are controlled with
\r
84 <literal>gc.rerereunresolved</literal> and <literal>gc.rerereresolved</literal> configuration
\r
91 <simplesect id="_discussion">
\r
92 <title>DISCUSSION</title>
\r
93 <simpara>When your topic branch modifies overlapping area that your
\r
94 master branch (or upstream) touched since your topic branch
\r
95 forked from it, you may want to test it with the latest master,
\r
96 even before your topic branch is ready to be pushed upstream:</simpara>
\r
97 <literallayout> o---*---o topic
\r
99 o---o---o---*---o---o master</literallayout>
\r
100 <simpara>For such a test, you need to merge master and topic somehow.
\r
101 One way to do it is to pull master into the topic branch:</simpara>
\r
102 <literallayout> $ git checkout topic
\r
105 o---*---o---+ topic
\r
107 o---o---o---*---o---o master</literallayout>
\r
108 <simpara>The commits marked with <literal>*</literal> touch the same area in the same
\r
109 file; you need to resolve the conflicts when creating the commit
\r
110 marked with <literal>+</literal>. Then you can test the result to make sure your
\r
111 work-in-progress still works with what is in the latest master.</simpara>
\r
112 <simpara>After this test merge, there are two ways to continue your work
\r
113 on the topic. The easiest is to build on top of the test merge
\r
114 commit <literal>+</literal>, and when your work in the topic branch is finally
\r
115 ready, pull the topic branch into master, and/or ask the
\r
116 upstream to pull from you. By that time, however, the master or
\r
117 the upstream might have been advanced since the test merge <literal>+</literal>,
\r
118 in which case the final commit graph would look like this:</simpara>
\r
119 <literallayout> $ git checkout topic
\r
121 $ ... work on both topic and master branches
\r
122 $ git checkout master
\r
125 o---*---o---+---o---o topic
\r
127 o---o---o---*---o---o---o---o---+ master</literallayout>
\r
128 <simpara>When your topic branch is long-lived, however, your topic branch
\r
129 would end up having many such "Merge from master" commits on it,
\r
130 which would unnecessarily clutter the development history.
\r
131 Readers of the Linux kernel mailing list may remember that Linus
\r
132 complained about such too frequent test merges when a subsystem
\r
133 maintainer asked to pull from a branch full of "useless merges".</simpara>
\r
134 <simpara>As an alternative, to keep the topic branch clean of test
\r
135 merges, you could blow away the test merge, and keep building on
\r
136 top of the tip before the test merge:</simpara>
\r
137 <literallayout> $ git checkout topic
\r
139 $ git reset --hard HEAD^ ;# rewind the test merge
\r
140 $ ... work on both topic and master branches
\r
141 $ git checkout master
\r
144 o---*---o-------o---o topic
\r
146 o---o---o---*---o---o---o---o---+ master</literallayout>
\r
147 <simpara>This would leave only one merge commit when your topic branch is
\r
148 finally ready and merged into the master branch. This merge
\r
149 would require you to resolve the conflict, introduced by the
\r
150 commits marked with <literal>*</literal>. However, often this conflict is the
\r
151 same conflict you resolved when you created the test merge you
\r
152 blew away. <emphasis>git-rerere</emphasis> command helps you to resolve this final
\r
153 conflicted merge using the information from your earlier hand
\r
155 <simpara>Running the <emphasis>git-rerere</emphasis> command immediately after a conflicted
\r
156 automerge records the conflicted working tree files, with the
\r
157 usual conflict markers <literal><<<<<<<</literal>, <literal>=======</literal>, and <literal>>>>>>>></literal> in
\r
158 them. Later, after you are done resolving the conflicts,
\r
159 running <emphasis>git-rerere</emphasis> again records the resolved state of these
\r
160 files. Suppose you did this when you created the test merge of
\r
161 master into the topic branch.</simpara>
\r
162 <simpara>Next time, running <emphasis>git-rerere</emphasis> after seeing a conflicted
\r
163 automerge, if the conflict is the same as the earlier one
\r
164 recorded, it is noticed and a three-way merge between the
\r
165 earlier conflicted automerge, the earlier manual resolution, and
\r
166 the current conflicted automerge is performed by the command.
\r
167 If this three-way merge resolves cleanly, the result is written
\r
168 out to your working tree file, so you would not have to manually
\r
169 resolve it. Note that <emphasis>git-rerere</emphasis> leaves the index file alone,
\r
170 so you still need to do the final sanity checks with <literal>git diff</literal>
\r
171 (or <literal>git diff -c</literal>) and <emphasis>git-add</emphasis> when you are satisfied.</simpara>
\r
172 <simpara>As a convenience measure, <emphasis>git-merge</emphasis> automatically invokes
\r
173 <emphasis>git-rerere</emphasis> when it exits with a failed automerge, which
\r
174 records it if it is a new conflict, or reuses the earlier hand
\r
175 resolve when it is not. <emphasis>git-commit</emphasis> also invokes <emphasis>git-rerere</emphasis>
\r
176 when recording a merge result. What this means is that you do
\r
177 not have to do anything special yourself (Note: you still have
\r
178 to set the config variable rerere.enabled to enable this command).</simpara>
\r
179 <simpara>In our example, when you did the test merge, the manual
\r
180 resolution is recorded, and it will be reused when you do the
\r
181 actual merge later with updated master and topic branch, as long
\r
182 as the earlier resolution is still applicable.</simpara>
\r
183 <simpara>The information <emphasis>git-rerere</emphasis> records is also used when running
\r
184 <emphasis>git-rebase</emphasis>. After blowing away the test merge and continuing
\r
185 development on the topic branch:</simpara>
\r
186 <literallayout> o---*---o-------o---o topic
\r
188 o---o---o---*---o---o---o---o master
\r
190 $ git rebase master topic
\r
192 o---*---o-------o---o topic
\r
194 o---o---o---*---o---o---o---o master</literallayout>
\r
195 <simpara>you could run <literal>git rebase master topic</literal>, to keep yourself
\r
196 up-to-date even before your topic is ready to be sent upstream.
\r
197 This would result in falling back to three-way merge, and it
\r
198 would conflict the same way the test merge you resolved earlier.
\r
199 <emphasis>git-rerere</emphasis> is run by <emphasis>git-rebase</emphasis> to help you resolve this
\r
200 conflict.</simpara>
\r
202 <simplesect id="_author">
\r
203 <title>Author</title>
\r
204 <simpara>Written by Junio C Hamano <<ulink url="mailto:gitster@pobox.com">gitster@pobox.com</ulink>></simpara>
\r
206 <simplesect id="_git">
\r
208 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
\r