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