updated git doc
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-rebase.xml
blob4547d42d2caf577436a5f089615516d16bfd9fa4
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-rebase(1)">\r
5 <articleinfo>\r
6     <title>git-rebase(1)</title>\r
7 <indexterm>\r
8 <primary>git-rebase(1)</primary>\r
9 </indexterm>\r
10 </articleinfo>\r
11 <simplesect id="_name">\r
12 <title>NAME</title>\r
13 <simpara>git-rebase - Forward-port local commits to the updated upstream head</simpara>\r
14 </simplesect>\r
15 <simplesect id="_synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git rebase</emphasis> [-i | --interactive] [options] [--onto &lt;newbase&gt;]\r
19         [&lt;upstream&gt;] [&lt;branch&gt;]\r
20 <emphasis>git rebase</emphasis> [-i | --interactive] [options] --onto &lt;newbase&gt;\r
21         --root [&lt;branch&gt;]\r
22 <emphasis>git rebase</emphasis> --continue | --skip | --abort</literallayout>\r
23 </blockquote>\r
24 </simplesect>\r
25 <simplesect id="_description">\r
26 <title>DESCRIPTION</title>\r
27 <simpara>If &lt;branch&gt; is specified, <emphasis>git rebase</emphasis> will perform an automatic\r
28 <emphasis>git checkout &lt;branch&gt;</emphasis> before doing anything else.  Otherwise\r
29 it remains on the current branch.</simpara>\r
30 <simpara>If &lt;upstream&gt; is not specified, the upstream configured in\r
31 branch.&lt;name&gt;.remote and branch.&lt;name&gt;.merge options will be used; see\r
32 <xref linkend="git-config(1)" /> for details.  If you are currently not on any\r
33 branch or if the current branch does not have a configured upstream,\r
34 the rebase will abort.</simpara>\r
35 <simpara>All changes made by commits in the current branch but that are not\r
36 in &lt;upstream&gt; are saved to a temporary area.  This is the same set\r
37 of commits that would be shown by <emphasis>git log &lt;upstream&gt;..HEAD</emphasis> (or\r
38 <emphasis>git log HEAD</emphasis>, if --root is specified).</simpara>\r
39 <simpara>The current branch is reset to &lt;upstream&gt;, or &lt;newbase&gt; if the\r
40 --onto option was supplied.  This has the exact same effect as\r
41 <emphasis>git reset --hard &lt;upstream&gt;</emphasis> (or &lt;newbase&gt;).  ORIG_HEAD is set\r
42 to point at the tip of the branch before the reset.</simpara>\r
43 <simpara>The commits that were previously saved into the temporary area are\r
44 then reapplied to the current branch, one by one, in order. Note that\r
45 any commits in HEAD which introduce the same textual changes as a commit\r
46 in HEAD..&lt;upstream&gt; are omitted (i.e., a patch already accepted upstream\r
47 with a different commit message or timestamp will be skipped).</simpara>\r
48 <simpara>It is possible that a merge failure will prevent this process from being\r
49 completely automatic.  You will have to resolve any such merge failure\r
50 and run <emphasis>git rebase --continue</emphasis>.  Another option is to bypass the commit\r
51 that caused the merge failure with <emphasis>git rebase --skip</emphasis>.  To check out the\r
52 original &lt;branch&gt; and remove the .git/rebase-apply working files, use the\r
53 command <emphasis>git rebase --abort</emphasis> instead.</simpara>\r
54 <simpara>Assume the following history exists and the current branch is "topic":</simpara>\r
55 <screen>          A---B---C topic\r
56          /\r
57     D---E---F---G master</screen>\r
58 <simpara>From this point, the result of either of the following commands:</simpara>\r
59 <literallayout class="monospaced">git rebase master\r
60 git rebase master topic</literallayout>\r
61 <simpara>would be:</simpara>\r
62 <screen>                  A'--B'--C' topic\r
63                  /\r
64     D---E---F---G master</screen>\r
65 <simpara><emphasis role="strong">NOTE:</emphasis> The latter form is just a short-hand of <emphasis>git checkout topic</emphasis>\r
66 followed by <emphasis>git rebase master</emphasis>. When rebase exits <emphasis>topic</emphasis> will\r
67 remain the checked-out branch.</simpara>\r
68 <simpara>If the upstream branch already contains a change you have made (e.g.,\r
69 because you mailed a patch which was applied upstream), then that commit\r
70 will be skipped. For example, running git rebase master` on the\r
71 following history (in which A and A introduce the same set of changes,\r
72 but have different committer information):</simpara>\r
73 <screen>          A---B---C topic\r
74          /\r
75     D---E---A'---F master</screen>\r
76 <simpara>will result in:</simpara>\r
77 <screen>                   B'---C' topic\r
78                   /\r
79     D---E---A'---F master</screen>\r
80 <simpara>Here is how you would transplant a topic branch based on one\r
81 branch to another, to pretend that you forked the topic branch\r
82 from the latter branch, using <emphasis>rebase --onto</emphasis>.</simpara>\r
83 <simpara>First let's assume your <emphasis>topic</emphasis> is based on branch <emphasis>next</emphasis>.\r
84 For example, a feature developed in <emphasis>topic</emphasis> depends on some\r
85 functionality which is found in <emphasis>next</emphasis>.</simpara>\r
86 <screen>    o---o---o---o---o  master\r
87          \\r
88           o---o---o---o---o  next\r
89                            \\r
90                             o---o---o  topic</screen>\r
91 <simpara>We want to make <emphasis>topic</emphasis> forked from branch <emphasis>master</emphasis>; for example,\r
92 because the functionality on which <emphasis>topic</emphasis> depends was merged into the\r
93 more stable <emphasis>master</emphasis> branch. We want our tree to look like this:</simpara>\r
94 <screen>    o---o---o---o---o  master\r
95         |            \\r
96         |             o'--o'--o'  topic\r
97          \\r
98           o---o---o---o---o  next</screen>\r
99 <simpara>We can get this using the following command:</simpara>\r
100 <literallayout class="monospaced">git rebase --onto master next topic</literallayout>\r
101 <simpara>Another example of --onto option is to rebase part of a\r
102 branch.  If we have the following situation:</simpara>\r
103 <screen>                            H---I---J topicB\r
104                            /\r
105                   E---F---G  topicA\r
106                  /\r
107     A---B---C---D  master</screen>\r
108 <simpara>then the command</simpara>\r
109 <literallayout class="monospaced">git rebase --onto master topicA topicB</literallayout>\r
110 <simpara>would result in:</simpara>\r
111 <screen>                 H'--I'--J'  topicB\r
112                 /\r
113                 | E---F---G  topicA\r
114                 |/\r
115     A---B---C---D  master</screen>\r
116 <simpara>This is useful when topicB does not depend on topicA.</simpara>\r
117 <simpara>A range of commits could also be removed with rebase.  If we have\r
118 the following situation:</simpara>\r
119 <screen>    E---F---G---H---I---J  topicA</screen>\r
120 <simpara>then the command</simpara>\r
121 <literallayout class="monospaced">git rebase --onto topicA~5 topicA~3 topicA</literallayout>\r
122 <simpara>would result in the removal of commits F and G:</simpara>\r
123 <screen>    E---H'---I'---J'  topicA</screen>\r
124 <simpara>This is useful if F and G were flawed in some way, or should not be\r
125 part of topicA.  Note that the argument to --onto and the &lt;upstream&gt;\r
126 parameter can be any valid commit-ish.</simpara>\r
127 <simpara>In case of conflict, <emphasis>git rebase</emphasis> will stop at the first problematic commit\r
128 and leave conflict markers in the tree.  You can use <emphasis>git diff</emphasis> to locate\r
129 the markers (&lt;&lt;&lt;&lt;&lt;&lt;) and make edits to resolve the conflict.  For each\r
130 file you edit, you need to tell git that the conflict has been resolved,\r
131 typically this would be done with</simpara>\r
132 <literallayout class="monospaced">git add &lt;filename&gt;</literallayout>\r
133 <simpara>After resolving the conflict manually and updating the index with the\r
134 desired resolution, you can continue the rebasing process with</simpara>\r
135 <literallayout class="monospaced">git rebase --continue</literallayout>\r
136 <simpara>Alternatively, you can undo the <emphasis>git rebase</emphasis> with</simpara>\r
137 <literallayout class="monospaced">git rebase --abort</literallayout>\r
138 </simplesect>\r
139 <simplesect id="_configuration">\r
140 <title>CONFIGURATION</title>\r
141 <variablelist>\r
142 <varlistentry>\r
143 <term>\r
144 rebase.stat\r
145 </term>\r
146 <listitem>\r
147 <simpara>\r
148         Whether to show a diffstat of what changed upstream since the last\r
149         rebase. False by default.\r
150 </simpara>\r
151 </listitem>\r
152 </varlistentry>\r
153 <varlistentry>\r
154 <term>\r
155 rebase.autosquash\r
156 </term>\r
157 <listitem>\r
158 <simpara>\r
159         If set to true enable <emphasis>--autosquash</emphasis> option by default.\r
160 </simpara>\r
161 </listitem>\r
162 </varlistentry>\r
163 </variablelist>\r
164 </simplesect>\r
165 <simplesect id="_options">\r
166 <title>OPTIONS</title>\r
167 <variablelist>\r
168 <varlistentry>\r
169 <term>\r
170 &lt;newbase&gt;\r
171 </term>\r
172 <listitem>\r
173 <simpara>\r
174         Starting point at which to create the new commits. If the\r
175         --onto option is not specified, the starting point is\r
176         &lt;upstream&gt;.  May be any valid commit, and not just an\r
177         existing branch name.\r
178 </simpara>\r
179 <simpara>As a special case, you may use "A...B" as a shortcut for the\r
180 merge base of A and B if there is exactly one merge base. You can\r
181 leave out at most one of A and B, in which case it defaults to HEAD.</simpara>\r
182 </listitem>\r
183 </varlistentry>\r
184 <varlistentry>\r
185 <term>\r
186 &lt;upstream&gt;\r
187 </term>\r
188 <listitem>\r
189 <simpara>\r
190         Upstream branch to compare against.  May be any valid commit,\r
191         not just an existing branch name. Defaults to the configured\r
192         upstream for the current branch.\r
193 </simpara>\r
194 </listitem>\r
195 </varlistentry>\r
196 <varlistentry>\r
197 <term>\r
198 &lt;branch&gt;\r
199 </term>\r
200 <listitem>\r
201 <simpara>\r
202         Working branch; defaults to HEAD.\r
203 </simpara>\r
204 </listitem>\r
205 </varlistentry>\r
206 <varlistentry>\r
207 <term>\r
208 --continue\r
209 </term>\r
210 <listitem>\r
211 <simpara>\r
212         Restart the rebasing process after having resolved a merge conflict.\r
213 </simpara>\r
214 </listitem>\r
215 </varlistentry>\r
216 <varlistentry>\r
217 <term>\r
218 --abort\r
219 </term>\r
220 <listitem>\r
221 <simpara>\r
222         Abort the rebase operation and reset HEAD to the original\r
223         branch. If &lt;branch&gt; was provided when the rebase operation was\r
224         started, then HEAD will be reset to &lt;branch&gt;. Otherwise HEAD\r
225         will be reset to where it was when the rebase operation was\r
226         started.\r
227 </simpara>\r
228 </listitem>\r
229 </varlistentry>\r
230 <varlistentry>\r
231 <term>\r
232 --skip\r
233 </term>\r
234 <listitem>\r
235 <simpara>\r
236         Restart the rebasing process by skipping the current patch.\r
237 </simpara>\r
238 </listitem>\r
239 </varlistentry>\r
240 <varlistentry>\r
241 <term>\r
242 -m\r
243 </term>\r
244 <term>\r
245 --merge\r
246 </term>\r
247 <listitem>\r
248 <simpara>\r
249         Use merging strategies to rebase.  When the recursive (default) merge\r
250         strategy is used, this allows rebase to be aware of renames on the\r
251         upstream side.\r
252 </simpara>\r
253 <simpara>Note that a rebase merge works by replaying each commit from the working\r
254 branch on top of the &lt;upstream&gt; branch.  Because of this, when a merge\r
255 conflict happens, the side reported as <emphasis>ours</emphasis> is the so-far rebased\r
256 series, starting with &lt;upstream&gt;, and <emphasis>theirs</emphasis> is the working branch.  In\r
257 other words, the sides are swapped.</simpara>\r
258 </listitem>\r
259 </varlistentry>\r
260 <varlistentry>\r
261 <term>\r
262 -s &lt;strategy&gt;\r
263 </term>\r
264 <term>\r
265 --strategy=&lt;strategy&gt;\r
266 </term>\r
267 <listitem>\r
268 <simpara>\r
269         Use the given merge strategy.\r
270         If there is no <emphasis>-s</emphasis> option <emphasis>git merge-recursive</emphasis> is used\r
271         instead.  This implies --merge.\r
272 </simpara>\r
273 <simpara>Because <emphasis>git rebase</emphasis> replays each commit from the working branch\r
274 on top of the &lt;upstream&gt; branch using the given strategy, using\r
275 the <emphasis>ours</emphasis> strategy simply discards all patches from the &lt;branch&gt;,\r
276 which makes little sense.</simpara>\r
277 </listitem>\r
278 </varlistentry>\r
279 <varlistentry>\r
280 <term>\r
281 -X &lt;strategy-option&gt;\r
282 </term>\r
283 <term>\r
284 --strategy-option=&lt;strategy-option&gt;\r
285 </term>\r
286 <listitem>\r
287 <simpara>\r
288         Pass the &lt;strategy-option&gt; through to the merge strategy.\r
289         This implies <emphasis>--merge</emphasis> and, if no strategy has been\r
290         specified, <emphasis>-s recursive</emphasis>.  Note the reversal of <emphasis>ours</emphasis> and\r
291         <emphasis>theirs</emphasis> as noted in above for the <emphasis>-m</emphasis> option.\r
292 </simpara>\r
293 </listitem>\r
294 </varlistentry>\r
295 <varlistentry>\r
296 <term>\r
297 -q\r
298 </term>\r
299 <term>\r
300 --quiet\r
301 </term>\r
302 <listitem>\r
303 <simpara>\r
304         Be quiet. Implies --no-stat.\r
305 </simpara>\r
306 </listitem>\r
307 </varlistentry>\r
308 <varlistentry>\r
309 <term>\r
310 -v\r
311 </term>\r
312 <term>\r
313 --verbose\r
314 </term>\r
315 <listitem>\r
316 <simpara>\r
317         Be verbose. Implies --stat.\r
318 </simpara>\r
319 </listitem>\r
320 </varlistentry>\r
321 <varlistentry>\r
322 <term>\r
323 --stat\r
324 </term>\r
325 <listitem>\r
326 <simpara>\r
327         Show a diffstat of what changed upstream since the last rebase. The\r
328         diffstat is also controlled by the configuration option rebase.stat.\r
329 </simpara>\r
330 </listitem>\r
331 </varlistentry>\r
332 <varlistentry>\r
333 <term>\r
334 -n\r
335 </term>\r
336 <term>\r
337 --no-stat\r
338 </term>\r
339 <listitem>\r
340 <simpara>\r
341         Do not show a diffstat as part of the rebase process.\r
342 </simpara>\r
343 </listitem>\r
344 </varlistentry>\r
345 <varlistentry>\r
346 <term>\r
347 --no-verify\r
348 </term>\r
349 <listitem>\r
350 <simpara>\r
351         This option bypasses the pre-rebase hook.  See also <xref linkend="githooks(5)" />.\r
352 </simpara>\r
353 </listitem>\r
354 </varlistentry>\r
355 <varlistentry>\r
356 <term>\r
357 --verify\r
358 </term>\r
359 <listitem>\r
360 <simpara>\r
361         Allows the pre-rebase hook to run, which is the default.  This option can\r
362         be used to override --no-verify.  See also <xref linkend="githooks(5)" />.\r
363 </simpara>\r
364 </listitem>\r
365 </varlistentry>\r
366 <varlistentry>\r
367 <term>\r
368 -C&lt;n&gt;\r
369 </term>\r
370 <listitem>\r
371 <simpara>\r
372         Ensure at least &lt;n&gt; lines of surrounding context match before\r
373         and after each change.  When fewer lines of surrounding\r
374         context exist they all must match.  By default no context is\r
375         ever ignored.\r
376 </simpara>\r
377 </listitem>\r
378 </varlistentry>\r
379 <varlistentry>\r
380 <term>\r
381 -f\r
382 </term>\r
383 <term>\r
384 --force-rebase\r
385 </term>\r
386 <listitem>\r
387 <simpara>\r
388         Force the rebase even if the current branch is a descendant\r
389         of the commit you are rebasing onto.  Normally non-interactive rebase will\r
390         exit with the message "Current branch is up to date" in such a\r
391         situation.\r
392         Incompatible with the --interactive option.\r
393 </simpara>\r
394 <simpara>You may find this (or --no-ff with an interactive rebase) helpful after\r
395 reverting a topic branch merge, as this option recreates the topic branch with\r
396 fresh commits so it can be remerged successfully without needing to "revert\r
397 the reversion" (see the\r
398 link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for details).</simpara>\r
399 </listitem>\r
400 </varlistentry>\r
401 <varlistentry>\r
402 <term>\r
403 --ignore-whitespace\r
404 </term>\r
405 <term>\r
406 --whitespace=&lt;option&gt;\r
407 </term>\r
408 <listitem>\r
409 <simpara>\r
410         These flag are passed to the <emphasis>git apply</emphasis> program\r
411         (see <xref linkend="git-apply(1)" />) that applies the patch.\r
412         Incompatible with the --interactive option.\r
413 </simpara>\r
414 </listitem>\r
415 </varlistentry>\r
416 <varlistentry>\r
417 <term>\r
418 --committer-date-is-author-date\r
419 </term>\r
420 <term>\r
421 --ignore-date\r
422 </term>\r
423 <listitem>\r
424 <simpara>\r
425         These flags are passed to <emphasis>git am</emphasis> to easily change the dates\r
426         of the rebased commits (see <xref linkend="git-am(1)" />).\r
427         Incompatible with the --interactive option.\r
428 </simpara>\r
429 </listitem>\r
430 </varlistentry>\r
431 <varlistentry>\r
432 <term>\r
433 -i\r
434 </term>\r
435 <term>\r
436 --interactive\r
437 </term>\r
438 <listitem>\r
439 <simpara>\r
440         Make a list of the commits which are about to be rebased.  Let the\r
441         user edit that list before rebasing.  This mode can also be used to\r
442         split commits (see SPLITTING COMMITS below).\r
443 </simpara>\r
444 </listitem>\r
445 </varlistentry>\r
446 <varlistentry>\r
447 <term>\r
448 -p\r
449 </term>\r
450 <term>\r
451 --preserve-merges\r
452 </term>\r
453 <listitem>\r
454 <simpara>\r
455         Instead of ignoring merges, try to recreate them.\r
456 </simpara>\r
457 <simpara>This uses the <emphasis>--interactive</emphasis> machinery internally, but combining it\r
458 with the <emphasis>--interactive</emphasis> option explicitly is generally not a good\r
459 idea unless you know what you are doing (see BUGS below).</simpara>\r
460 </listitem>\r
461 </varlistentry>\r
462 <varlistentry>\r
463 <term>\r
464 --root\r
465 </term>\r
466 <listitem>\r
467 <simpara>\r
468         Rebase all commits reachable from &lt;branch&gt;, instead of\r
469         limiting them with an &lt;upstream&gt;.  This allows you to rebase\r
470         the root commit(s) on a branch.  Must be used with --onto, and\r
471         will skip changes already contained in &lt;newbase&gt; (instead of\r
472         &lt;upstream&gt;).  When used together with --preserve-merges, <emphasis>all</emphasis>\r
473         root commits will be rewritten to have &lt;newbase&gt; as parent\r
474         instead.\r
475 </simpara>\r
476 </listitem>\r
477 </varlistentry>\r
478 <varlistentry>\r
479 <term>\r
480 --autosquash\r
481 </term>\r
482 <term>\r
483 --no-autosquash\r
484 </term>\r
485 <listitem>\r
486 <simpara>\r
487         When the commit log message begins with "squash! &#8230;" (or\r
488         "fixup! &#8230;"), and there is a commit whose title begins with\r
489         the same &#8230;, automatically modify the todo list of rebase -i\r
490         so that the commit marked for squashing comes right after the\r
491         commit to be modified, and change the action of the moved\r
492         commit from <emphasis>pick</emphasis> to <emphasis>squash</emphasis> (or <emphasis>fixup</emphasis>).\r
493 </simpara>\r
494 <simpara>This option is only valid when the <emphasis>--interactive</emphasis> option is used.</simpara>\r
495 <simpara>If the <emphasis>--autosquash</emphasis> option is enabled by default using the\r
496 configuration variable <emphasis>rebase.autosquash</emphasis>, this option can be\r
497 used to override and disable this setting.</simpara>\r
498 </listitem>\r
499 </varlistentry>\r
500 <varlistentry>\r
501 <term>\r
502 --no-ff\r
503 </term>\r
504 <listitem>\r
505 <simpara>\r
506         With --interactive, cherry-pick all rebased commits instead of\r
507         fast-forwarding over the unchanged ones.  This ensures that the\r
508         entire history of the rebased branch is composed of new commits.\r
509 </simpara>\r
510 <simpara>Without --interactive, this is a synonym for --force-rebase.</simpara>\r
511 <simpara>You may find this helpful after reverting a topic branch merge, as this option\r
512 recreates the topic branch with fresh commits so it can be remerged\r
513 successfully without needing to "revert the reversion" (see the\r
514 link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for details).</simpara>\r
515 </listitem>\r
516 </varlistentry>\r
517 </variablelist>\r
518 </simplesect>\r
519 <simplesect id="_merge_strategies">\r
520 <title>MERGE STRATEGIES</title>\r
521 <simpara>The merge mechanism (<emphasis>git-merge</emphasis> and <emphasis>git-pull</emphasis> commands) allows the\r
522 backend <emphasis>merge strategies</emphasis> to be chosen with <emphasis>-s</emphasis> option.  Some strategies\r
523 can also take their own options, which can be passed by giving <emphasis>-X&lt;option&gt;</emphasis>\r
524 arguments to <emphasis>git-merge</emphasis> and/or <emphasis>git-pull</emphasis>.</simpara>\r
525 <variablelist>\r
526 <varlistentry>\r
527 <term>\r
528 resolve\r
529 </term>\r
530 <listitem>\r
531 <simpara>\r
532         This can only resolve two heads (i.e. the current branch\r
533         and another branch you pulled from) using a 3-way merge\r
534         algorithm.  It tries to carefully detect criss-cross\r
535         merge ambiguities and is considered generally safe and\r
536         fast.\r
537 </simpara>\r
538 </listitem>\r
539 </varlistentry>\r
540 <varlistentry>\r
541 <term>\r
542 recursive\r
543 </term>\r
544 <listitem>\r
545 <simpara>\r
546         This can only resolve two heads using a 3-way merge\r
547         algorithm.  When there is more than one common\r
548         ancestor that can be used for 3-way merge, it creates a\r
549         merged tree of the common ancestors and uses that as\r
550         the reference tree for the 3-way merge.  This has been\r
551         reported to result in fewer merge conflicts without\r
552         causing mis-merges by tests done on actual merge commits\r
553         taken from Linux 2.6 kernel development history.\r
554         Additionally this can detect and handle merges involving\r
555         renames.  This is the default merge strategy when\r
556         pulling or merging one branch.\r
557 </simpara>\r
558 <simpara>The <emphasis>recursive</emphasis> strategy can take the following options:</simpara>\r
559 <variablelist>\r
560 <varlistentry>\r
561 <term>\r
562 ours\r
563 </term>\r
564 <listitem>\r
565 <simpara>\r
566         This option forces conflicting hunks to be auto-resolved cleanly by\r
567         favoring <emphasis>our</emphasis> version.  Changes from the other tree that do not\r
568         conflict with our side are reflected to the merge result.\r
569 </simpara>\r
570 <simpara>This should not be confused with the <emphasis>ours</emphasis> merge strategy, which does not\r
571 even look at what the other tree contains at all.  It discards everything\r
572 the other tree did, declaring <emphasis>our</emphasis> history contains all that happened in it.</simpara>\r
573 </listitem>\r
574 </varlistentry>\r
575 <varlistentry>\r
576 <term>\r
577 theirs\r
578 </term>\r
579 <listitem>\r
580 <simpara>\r
581         This is opposite of <emphasis>ours</emphasis>.\r
582 </simpara>\r
583 </listitem>\r
584 </varlistentry>\r
585 <varlistentry>\r
586 <term>\r
587 patience\r
588 </term>\r
589 <listitem>\r
590 <simpara>\r
591         With this option, <emphasis>merge-recursive</emphasis> spends a little extra time\r
592         to avoid mismerges that sometimes occur due to unimportant\r
593         matching lines (e.g., braces from distinct functions).  Use\r
594         this when the branches to be merged have diverged wildly.\r
595         See also <xref linkend="git-diff(1)" /> <emphasis>--patience</emphasis>.\r
596 </simpara>\r
597 </listitem>\r
598 </varlistentry>\r
599 <varlistentry>\r
600 <term>\r
601 ignore-space-change\r
602 </term>\r
603 <term>\r
604 ignore-all-space\r
605 </term>\r
606 <term>\r
607 ignore-space-at-eol\r
608 </term>\r
609 <listitem>\r
610 <simpara>\r
611         Treats lines with the indicated type of whitespace change as\r
612         unchanged for the sake of a three-way merge.  Whitespace\r
613         changes mixed with other changes to a line are not ignored.\r
614         See also <xref linkend="git-diff(1)" /> <emphasis>-b</emphasis>, <emphasis>-w</emphasis>, and\r
615         <emphasis>--ignore-space-at-eol</emphasis>.\r
616 </simpara>\r
617 <itemizedlist>\r
618 <listitem>\r
619 <simpara>\r
620 If <emphasis>their</emphasis> version only introduces whitespace changes to a line,\r
621   <emphasis>our</emphasis> version is used;\r
622 </simpara>\r
623 </listitem>\r
624 <listitem>\r
625 <simpara>\r
626 If <emphasis>our</emphasis> version introduces whitespace changes but <emphasis>their</emphasis>\r
627   version includes a substantial change, <emphasis>their</emphasis> version is used;\r
628 </simpara>\r
629 </listitem>\r
630 <listitem>\r
631 <simpara>\r
632 Otherwise, the merge proceeds in the usual way.\r
633 </simpara>\r
634 </listitem>\r
635 </itemizedlist>\r
636 </listitem>\r
637 </varlistentry>\r
638 <varlistentry>\r
639 <term>\r
640 renormalize\r
641 </term>\r
642 <listitem>\r
643 <simpara>\r
644         This runs a virtual check-out and check-in of all three stages\r
645         of a file when resolving a three-way merge.  This option is\r
646         meant to be used when merging branches with different clean\r
647         filters or end-of-line normalization rules.  See "Merging\r
648         branches with differing checkin/checkout attributes" in\r
649         <xref linkend="gitattributes(5)" /> for details.\r
650 </simpara>\r
651 </listitem>\r
652 </varlistentry>\r
653 <varlistentry>\r
654 <term>\r
655 no-renormalize\r
656 </term>\r
657 <listitem>\r
658 <simpara>\r
659         Disables the <emphasis>renormalize</emphasis> option.  This overrides the\r
660         <emphasis>merge.renormalize</emphasis> configuration variable.\r
661 </simpara>\r
662 </listitem>\r
663 </varlistentry>\r
664 <varlistentry>\r
665 <term>\r
666 rename-threshold=&lt;n&gt;\r
667 </term>\r
668 <listitem>\r
669 <simpara>\r
670         Controls the similarity threshold used for rename detection.\r
671         See also <xref linkend="git-diff(1)" /> <emphasis>-M</emphasis>.\r
672 </simpara>\r
673 </listitem>\r
674 </varlistentry>\r
675 <varlistentry>\r
676 <term>\r
677 subtree[=&lt;path&gt;]\r
678 </term>\r
679 <listitem>\r
680 <simpara>\r
681         This option is a more advanced form of <emphasis>subtree</emphasis> strategy, where\r
682         the strategy makes a guess on how two trees must be shifted to\r
683         match with each other when merging.  Instead, the specified path\r
684         is prefixed (or stripped from the beginning) to make the shape of\r
685         two trees to match.\r
686 </simpara>\r
687 </listitem>\r
688 </varlistentry>\r
689 </variablelist>\r
690 </listitem>\r
691 </varlistentry>\r
692 <varlistentry>\r
693 <term>\r
694 octopus\r
695 </term>\r
696 <listitem>\r
697 <simpara>\r
698         This resolves cases with more than two heads, but refuses to do\r
699         a complex merge that needs manual resolution.  It is\r
700         primarily meant to be used for bundling topic branch\r
701         heads together.  This is the default merge strategy when\r
702         pulling or merging more than one branch.\r
703 </simpara>\r
704 </listitem>\r
705 </varlistentry>\r
706 <varlistentry>\r
707 <term>\r
708 ours\r
709 </term>\r
710 <listitem>\r
711 <simpara>\r
712         This resolves any number of heads, but the resulting tree of the\r
713         merge is always that of the current branch head, effectively\r
714         ignoring all changes from all other branches.  It is meant to\r
715         be used to supersede old development history of side\r
716         branches.  Note that this is different from the -Xours option to\r
717         the <emphasis>recursive</emphasis> merge strategy.\r
718 </simpara>\r
719 </listitem>\r
720 </varlistentry>\r
721 <varlistentry>\r
722 <term>\r
723 subtree\r
724 </term>\r
725 <listitem>\r
726 <simpara>\r
727         This is a modified recursive strategy. When merging trees A and\r
728         B, if B corresponds to a subtree of A, B is first adjusted to\r
729         match the tree structure of A, instead of reading the trees at\r
730         the same level. This adjustment is also done to the common\r
731         ancestor tree.\r
732 </simpara>\r
733 </listitem>\r
734 </varlistentry>\r
735 </variablelist>\r
736 </simplesect>\r
737 <simplesect id="_notes">\r
738 <title>NOTES</title>\r
739 <simpara>You should understand the implications of using <emphasis>git rebase</emphasis> on a\r
740 repository that you share.  See also RECOVERING FROM UPSTREAM REBASE\r
741 below.</simpara>\r
742 <simpara>When the git-rebase command is run, it will first execute a "pre-rebase"\r
743 hook if one exists.  You can use this hook to do sanity checks and\r
744 reject the rebase if it isn't appropriate.  Please see the template\r
745 pre-rebase hook script for an example.</simpara>\r
746 <simpara>Upon completion, &lt;branch&gt; will be the current branch.</simpara>\r
747 </simplesect>\r
748 <simplesect id="_interactive_mode">\r
749 <title>INTERACTIVE MODE</title>\r
750 <simpara>Rebasing interactively means that you have a chance to edit the commits\r
751 which are rebased.  You can reorder the commits, and you can\r
752 remove them (weeding out bad or otherwise unwanted patches).</simpara>\r
753 <simpara>The interactive mode is meant for this type of workflow:</simpara>\r
754 <orderedlist numeration="arabic">\r
755 <listitem>\r
756 <simpara>\r
757 have a wonderful idea\r
758 </simpara>\r
759 </listitem>\r
760 <listitem>\r
761 <simpara>\r
762 hack on the code\r
763 </simpara>\r
764 </listitem>\r
765 <listitem>\r
766 <simpara>\r
767 prepare a series for submission\r
768 </simpara>\r
769 </listitem>\r
770 <listitem>\r
771 <simpara>\r
772 submit\r
773 </simpara>\r
774 </listitem>\r
775 </orderedlist>\r
776 <simpara>where point 2. consists of several instances of</simpara>\r
777 <simpara>a) regular use</simpara>\r
778 <orderedlist numeration="arabic">\r
779 <listitem>\r
780 <simpara>\r
781 finish something worthy of a commit\r
782 </simpara>\r
783 </listitem>\r
784 <listitem>\r
785 <simpara>\r
786 commit\r
787 </simpara>\r
788 </listitem>\r
789 </orderedlist>\r
790 <simpara>b) independent fixup</simpara>\r
791 <orderedlist numeration="arabic">\r
792 <listitem>\r
793 <simpara>\r
794 realize that something does not work\r
795 </simpara>\r
796 </listitem>\r
797 <listitem>\r
798 <simpara>\r
799 fix that\r
800 </simpara>\r
801 </listitem>\r
802 <listitem>\r
803 <simpara>\r
804 commit it\r
805 </simpara>\r
806 </listitem>\r
807 </orderedlist>\r
808 <simpara>Sometimes the thing fixed in b.2. cannot be amended to the not-quite\r
809 perfect commit it fixes, because that commit is buried deeply in a\r
810 patch series.  That is exactly what interactive rebase is for: use it\r
811 after plenty of "a"s and "b"s, by rearranging and editing\r
812 commits, and squashing multiple commits into one.</simpara>\r
813 <simpara>Start it with the last commit you want to retain as-is:</simpara>\r
814 <literallayout class="monospaced">git rebase -i &lt;after-this-commit&gt;</literallayout>\r
815 <simpara>An editor will be fired up with all the commits in your current branch\r
816 (ignoring merge commits), which come after the given commit.  You can\r
817 reorder the commits in this list to your heart's content, and you can\r
818 remove them.  The list looks more or less like this:</simpara>\r
819 <screen>pick deadbee The oneline of this commit\r
820 pick fa1afe1 The oneline of the next commit\r
821 ...</screen>\r
822 <simpara>The oneline descriptions are purely for your pleasure; <emphasis>git rebase</emphasis> will\r
823 not look at them but at the commit names ("deadbee" and "fa1afe1" in this\r
824 example), so do not delete or edit the names.</simpara>\r
825 <simpara>By replacing the command "pick" with the command "edit", you can tell\r
826 <emphasis>git rebase</emphasis> to stop after applying that commit, so that you can edit\r
827 the files and/or the commit message, amend the commit, and continue\r
828 rebasing.</simpara>\r
829 <simpara>If you just want to edit the commit message for a commit, replace the\r
830 command "pick" with the command "reword".</simpara>\r
831 <simpara>If you want to fold two or more commits into one, replace the command\r
832 "pick" for the second and subsequent commits with "squash" or "fixup".\r
833 If the commits had different authors, the folded commit will be\r
834 attributed to the author of the first commit.  The suggested commit\r
835 message for the folded commit is the concatenation of the commit\r
836 messages of the first commit and of those with the "squash" command,\r
837 but omits the commit messages of commits with the "fixup" command.</simpara>\r
838 <simpara><emphasis>git rebase</emphasis> will stop when "pick" has been replaced with "edit" or\r
839 when a command fails due to merge errors. When you are done editing\r
840 and/or resolving conflicts you can continue with <emphasis>git rebase --continue</emphasis>.</simpara>\r
841 <simpara>For example, if you want to reorder the last 5 commits, such that what\r
842 was HEAD~4 becomes the new HEAD. To achieve that, you would call\r
843 <emphasis>git rebase</emphasis> like this:</simpara>\r
844 <screen>$ git rebase -i HEAD~5</screen>\r
845 <simpara>And move the first patch to the end of the list.</simpara>\r
846 <simpara>You might want to preserve merges, if you have a history like this:</simpara>\r
847 <screen>           X\r
848             \\r
849          A---M---B\r
850         /\r
851 ---o---O---P---Q</screen>\r
852 <simpara>Suppose you want to rebase the side branch starting at "A" to "Q". Make\r
853 sure that the current HEAD is "B", and call</simpara>\r
854 <screen>$ git rebase -i -p --onto Q O</screen>\r
855 <simpara>Reordering and editing commits usually creates untested intermediate\r
856 steps.  You may want to check that your history editing did not break\r
857 anything by running a test, or at least recompiling at intermediate\r
858 points in history by using the "exec" command (shortcut "x").  You may\r
859 do so by creating a todo list like this one:</simpara>\r
860 <screen>pick deadbee Implement feature XXX\r
861 fixup f1a5c00 Fix to feature XXX\r
862 exec make\r
863 pick c0ffeee The oneline of the next commit\r
864 edit deadbab The oneline of the commit after\r
865 exec cd subdir; make test\r
866 ...</screen>\r
867 <simpara>The interactive rebase will stop when a command fails (i.e. exits with\r
868 non-0 status) to give you an opportunity to fix the problem. You can\r
869 continue with <emphasis>git rebase --continue</emphasis>.</simpara>\r
870 <simpara>The "exec" command launches the command in a shell (the one specified\r
871 in <emphasis>$SHELL</emphasis>, or the default shell if <emphasis>$SHELL</emphasis> is not set), so you can\r
872 use shell features (like "cd", "&gt;", ";" &#8230;). The command is run from\r
873 the root of the working tree.</simpara>\r
874 </simplesect>\r
875 <simplesect id="_splitting_commits">\r
876 <title>SPLITTING COMMITS</title>\r
877 <simpara>In interactive mode, you can mark commits with the action "edit".  However,\r
878 this does not necessarily mean that <emphasis>git rebase</emphasis> expects the result of this\r
879 edit to be exactly one commit.  Indeed, you can undo the commit, or you can\r
880 add other commits.  This can be used to split a commit into two:</simpara>\r
881 <itemizedlist>\r
882 <listitem>\r
883 <simpara>\r
884 Start an interactive rebase with <emphasis>git rebase -i &lt;commit&gt;^</emphasis>, where\r
885   &lt;commit&gt; is the commit you want to split.  In fact, any commit range\r
886   will do, as long as it contains that commit.\r
887 </simpara>\r
888 </listitem>\r
889 <listitem>\r
890 <simpara>\r
891 Mark the commit you want to split with the action "edit".\r
892 </simpara>\r
893 </listitem>\r
894 <listitem>\r
895 <simpara>\r
896 When it comes to editing that commit, execute <emphasis>git reset HEAD^</emphasis>.  The\r
897   effect is that the HEAD is rewound by one, and the index follows suit.\r
898   However, the working tree stays the same.\r
899 </simpara>\r
900 </listitem>\r
901 <listitem>\r
902 <simpara>\r
903 Now add the changes to the index that you want to have in the first\r
904   commit.  You can use <emphasis>git add</emphasis> (possibly interactively) or\r
905   <emphasis>git gui</emphasis> (or both) to do that.\r
906 </simpara>\r
907 </listitem>\r
908 <listitem>\r
909 <simpara>\r
910 Commit the now-current index with whatever commit message is appropriate\r
911   now.\r
912 </simpara>\r
913 </listitem>\r
914 <listitem>\r
915 <simpara>\r
916 Repeat the last two steps until your working tree is clean.\r
917 </simpara>\r
918 </listitem>\r
919 <listitem>\r
920 <simpara>\r
921 Continue the rebase with <emphasis>git rebase --continue</emphasis>.\r
922 </simpara>\r
923 </listitem>\r
924 </itemizedlist>\r
925 <simpara>If you are not absolutely sure that the intermediate revisions are\r
926 consistent (they compile, pass the testsuite, etc.) you should use\r
927 <emphasis>git stash</emphasis> to stash away the not-yet-committed changes\r
928 after each commit, test, and amend the commit if fixes are necessary.</simpara>\r
929 </simplesect>\r
930 <simplesect id="_recovering_from_upstream_rebase">\r
931 <title>RECOVERING FROM UPSTREAM REBASE</title>\r
932 <simpara>Rebasing (or any other form of rewriting) a branch that others have\r
933 based work on is a bad idea: anyone downstream of it is forced to\r
934 manually fix their history.  This section explains how to do the fix\r
935 from the downstream's point of view.  The real fix, however, would be\r
936 to avoid rebasing the upstream in the first place.</simpara>\r
937 <simpara>To illustrate, suppose you are in a situation where someone develops a\r
938 <emphasis>subsystem</emphasis> branch, and you are working on a <emphasis>topic</emphasis> that is dependent\r
939 on this <emphasis>subsystem</emphasis>.  You might end up with a history like the\r
940 following:</simpara>\r
941 <screen>    o---o---o---o---o---o---o---o---o  master\r
942          \\r
943           o---o---o---o---o  subsystem\r
944                            \\r
945                             *---*---*  topic</screen>\r
946 <simpara>If <emphasis>subsystem</emphasis> is rebased against <emphasis>master</emphasis>, the following happens:</simpara>\r
947 <screen>    o---o---o---o---o---o---o---o  master\r
948          \                       \\r
949           o---o---o---o---o       o'--o'--o'--o'--o'  subsystem\r
950                            \\r
951                             *---*---*  topic</screen>\r
952 <simpara>If you now continue development as usual, and eventually merge <emphasis>topic</emphasis>\r
953 to <emphasis>subsystem</emphasis>, the commits from <emphasis>subsystem</emphasis> will remain duplicated forever:</simpara>\r
954 <screen>    o---o---o---o---o---o---o---o  master\r
955          \                       \\r
956           o---o---o---o---o       o'--o'--o'--o'--o'--M  subsystem\r
957                            \                         /\r
958                             *---*---*-..........-*--*  topic</screen>\r
959 <simpara>Such duplicates are generally frowned upon because they clutter up\r
960 history, making it harder to follow.  To clean things up, you need to\r
961 transplant the commits on <emphasis>topic</emphasis> to the new <emphasis>subsystem</emphasis> tip, i.e.,\r
962 rebase <emphasis>topic</emphasis>.  This becomes a ripple effect: anyone downstream from\r
963 <emphasis>topic</emphasis> is forced to rebase too, and so on!</simpara>\r
964 <simpara>There are two kinds of fixes, discussed in the following subsections:</simpara>\r
965 <variablelist>\r
966 <varlistentry>\r
967 <term>\r
968 Easy case: The changes are literally the same.\r
969 </term>\r
970 <listitem>\r
971 <simpara>\r
972         This happens if the <emphasis>subsystem</emphasis> rebase was a simple rebase and\r
973         had no conflicts.\r
974 </simpara>\r
975 </listitem>\r
976 </varlistentry>\r
977 <varlistentry>\r
978 <term>\r
979 Hard case: The changes are not the same.\r
980 </term>\r
981 <listitem>\r
982 <simpara>\r
983         This happens if the <emphasis>subsystem</emphasis> rebase had conflicts, or used\r
984         <emphasis>--interactive</emphasis> to omit, edit, squash, or fixup commits; or\r
985         if the upstream used one of <emphasis>commit --amend</emphasis>, <emphasis>reset</emphasis>, or\r
986         <emphasis>filter-branch</emphasis>.\r
987 </simpara>\r
988 </listitem>\r
989 </varlistentry>\r
990 </variablelist>\r
991 <section id="_the_easy_case">\r
992 <title>The easy case</title>\r
993 <simpara>Only works if the changes (patch IDs based on the diff contents) on\r
994 <emphasis>subsystem</emphasis> are literally the same before and after the rebase\r
995 <emphasis>subsystem</emphasis> did.</simpara>\r
996 <simpara>In that case, the fix is easy because <emphasis>git rebase</emphasis> knows to skip\r
997 changes that are already present in the new upstream.  So if you say\r
998 (assuming you're on <emphasis>topic</emphasis>)</simpara>\r
999 <screen>    $ git rebase subsystem</screen>\r
1000 <simpara>you will end up with the fixed history</simpara>\r
1001 <screen>    o---o---o---o---o---o---o---o  master\r
1002                                  \\r
1003                                   o'--o'--o'--o'--o'  subsystem\r
1004                                                    \\r
1005                                                     *---*---*  topic</screen>\r
1006 </section>\r
1007 <section id="_the_hard_case">\r
1008 <title>The hard case</title>\r
1009 <simpara>Things get more complicated if the <emphasis>subsystem</emphasis> changes do not exactly\r
1010 correspond to the ones before the rebase.</simpara>\r
1011 <note><simpara>While an "easy case recovery" sometimes appears to be successful\r
1012       even in the hard case, it may have unintended consequences.  For\r
1013       example, a commit that was removed via <emphasis>git rebase\r
1014       --interactive</emphasis> will be <emphasis role="strong">resurrected</emphasis>!</simpara></note>\r
1015 <simpara>The idea is to manually tell <emphasis>git rebase</emphasis> "where the old <emphasis>subsystem</emphasis>\r
1016 ended and your <emphasis>topic</emphasis> began", that is, what the old merge-base\r
1017 between them was.  You will have to find a way to name the last commit\r
1018 of the old <emphasis>subsystem</emphasis>, for example:</simpara>\r
1019 <itemizedlist>\r
1020 <listitem>\r
1021 <simpara>\r
1022 With the <emphasis>subsystem</emphasis> reflog: after <emphasis>git fetch</emphasis>, the old tip of\r
1023   <emphasis>subsystem</emphasis> is at <emphasis>subsystem@{1}</emphasis>.  Subsequent fetches will\r
1024   increase the number.  (See <xref linkend="git-reflog(1)" />.)\r
1025 </simpara>\r
1026 </listitem>\r
1027 <listitem>\r
1028 <simpara>\r
1029 Relative to the tip of <emphasis>topic</emphasis>: knowing that your <emphasis>topic</emphasis> has three\r
1030   commits, the old tip of <emphasis>subsystem</emphasis> must be <emphasis>topic~3</emphasis>.\r
1031 </simpara>\r
1032 </listitem>\r
1033 </itemizedlist>\r
1034 <simpara>You can then transplant the old <emphasis>subsystem..topic</emphasis> to the new tip by\r
1035 saying (for the reflog case, and assuming you are on <emphasis>topic</emphasis> already):</simpara>\r
1036 <screen>    $ git rebase --onto subsystem subsystem@{1}</screen>\r
1037 <simpara>The ripple effect of a "hard case" recovery is especially bad:\r
1038 <emphasis>everyone</emphasis> downstream from <emphasis>topic</emphasis> will now have to perform a "hard\r
1039 case" recovery too!</simpara>\r
1040 </section>\r
1041 </simplesect>\r
1042 <simplesect id="_bugs">\r
1043 <title>BUGS</title>\r
1044 <simpara>The todo list presented by <emphasis>--preserve-merges --interactive</emphasis> does not\r
1045 represent the topology of the revision graph.  Editing commits and\r
1046 rewording their commit messages should work fine, but attempts to\r
1047 reorder commits tend to produce counterintuitive results.</simpara>\r
1048 <simpara>For example, an attempt to rearrange</simpara>\r
1049 <screen>1 --- 2 --- 3 --- 4 --- 5</screen>\r
1050 <simpara>to</simpara>\r
1051 <screen>1 --- 2 --- 4 --- 3 --- 5</screen>\r
1052 <simpara>by moving the "pick 4" line will result in the following history:</simpara>\r
1053 <screen>        3\r
1054        /\r
1055 1 --- 2 --- 4 --- 5</screen>\r
1056 </simplesect>\r
1057 <simplesect id="_git">\r
1058 <title>GIT</title>\r
1059 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
1060 </simplesect>\r
1061 </article>\r