Autogenerated HTML docs for v1.7.7-rc2-4-g5ec82
[git/jnareb-git.git] / git-rebase.html
blob9ea1f9645e775ea515b9f41b1a3e5898d5de5062
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.5.2" />
7 <title>git-rebase(1)</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
12 border: 1px solid red;
16 body {
17 margin: 1em 5% 1em 5%;
20 a {
21 color: blue;
22 text-decoration: underline;
24 a:visited {
25 color: fuchsia;
28 em {
29 font-style: italic;
30 color: navy;
33 strong {
34 font-weight: bold;
35 color: #083194;
38 tt {
39 color: navy;
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
53 h2 {
54 padding-top: 0.5em;
56 h3 {
57 float: left;
59 h3 + * {
60 clear: left;
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
68 hr {
69 border: 1px solid silver;
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
77 ul, ol, li > p {
78 margin-top: 0;
81 pre {
82 padding: 0;
83 margin: 0;
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
92 span#email {
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.0em;
122 margin-bottom: 1.5em;
124 div.admonitionblock {
125 margin-top: 2.0em;
126 margin-bottom: 2.0em;
127 margin-right: 10%;
128 color: #606060;
131 div.content { /* Block element content. */
132 padding: 0;
135 /* Block element titles. */
136 div.title, caption.title {
137 color: #527bbd;
138 font-family: sans-serif;
139 font-weight: bold;
140 text-align: left;
141 margin-top: 1.0em;
142 margin-bottom: 0.5em;
144 div.title + * {
145 margin-top: 0;
148 td div.title:first-child {
149 margin-top: 0.0em;
151 div.content div.title:first-child {
152 margin-top: 0.0em;
154 div.content + div.title {
155 margin-top: 0.0em;
158 div.sidebarblock > div.content {
159 background: #ffffee;
160 border: 1px solid silver;
161 padding: 0.5em;
164 div.listingblock > div.content {
165 border: 1px solid silver;
166 background: #f4f4f4;
167 padding: 0.5em;
170 div.quoteblock, div.verseblock {
171 padding-left: 1.0em;
172 margin-left: 1.0em;
173 margin-right: 10%;
174 border-left: 5px solid #dddddd;
175 color: #777777;
178 div.quoteblock > div.attribution {
179 padding-top: 0.5em;
180 text-align: right;
183 div.verseblock > div.content {
184 white-space: pre;
186 div.verseblock > div.attribution {
187 padding-top: 0.75em;
188 text-align: left;
190 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
191 div.verseblock + div.attribution {
192 text-align: left;
195 div.admonitionblock .icon {
196 vertical-align: top;
197 font-size: 1.1em;
198 font-weight: bold;
199 text-decoration: underline;
200 color: #527bbd;
201 padding-right: 0.5em;
203 div.admonitionblock td.content {
204 padding-left: 0.5em;
205 border-left: 3px solid #dddddd;
208 div.exampleblock > div.content {
209 border-left: 3px solid #dddddd;
210 padding-left: 0.5em;
213 div.imageblock div.content { padding-left: 0; }
214 span.image img { border-style: none; }
215 a.image:visited { color: white; }
217 dl {
218 margin-top: 0.8em;
219 margin-bottom: 0.8em;
221 dt {
222 margin-top: 0.5em;
223 margin-bottom: 0;
224 font-style: normal;
225 color: navy;
227 dd > *:first-child {
228 margin-top: 0.1em;
231 ul, ol {
232 list-style-position: outside;
234 ol.arabic {
235 list-style-type: decimal;
237 ol.loweralpha {
238 list-style-type: lower-alpha;
240 ol.upperalpha {
241 list-style-type: upper-alpha;
243 ol.lowerroman {
244 list-style-type: lower-roman;
246 ol.upperroman {
247 list-style-type: upper-roman;
250 div.compact ul, div.compact ol,
251 div.compact p, div.compact p,
252 div.compact div, div.compact div {
253 margin-top: 0.1em;
254 margin-bottom: 0.1em;
257 div.tableblock > table {
258 border: 3px solid #527bbd;
260 thead, p.table.header {
261 font-family: sans-serif;
262 font-weight: bold;
264 tfoot {
265 font-weight: bold;
267 td > div.verse {
268 white-space: pre;
270 p.table {
271 margin-top: 0;
273 /* Because the table frame attribute is overriden by CSS in most browsers. */
274 div.tableblock > table[frame="void"] {
275 border-style: none;
277 div.tableblock > table[frame="hsides"] {
278 border-left-style: none;
279 border-right-style: none;
281 div.tableblock > table[frame="vsides"] {
282 border-top-style: none;
283 border-bottom-style: none;
287 div.hdlist {
288 margin-top: 0.8em;
289 margin-bottom: 0.8em;
291 div.hdlist tr {
292 padding-bottom: 15px;
294 dt.hdlist1.strong, td.hdlist1.strong {
295 font-weight: bold;
297 td.hdlist1 {
298 vertical-align: top;
299 font-style: normal;
300 padding-right: 0.8em;
301 color: navy;
303 td.hdlist2 {
304 vertical-align: top;
306 div.hdlist.compact tr {
307 margin: 0;
308 padding-bottom: 0;
311 .comment {
312 background: yellow;
315 .footnote, .footnoteref {
316 font-size: 0.8em;
319 span.footnote, span.footnoteref {
320 vertical-align: super;
323 #footnotes {
324 margin: 20px 0 20px 0;
325 padding: 7px 0 0 0;
328 #footnotes div.footnote {
329 margin: 0 0 5px 0;
332 #footnotes hr {
333 border: none;
334 border-top: 1px solid silver;
335 height: 1px;
336 text-align: left;
337 margin-left: 0;
338 width: 20%;
339 min-width: 100px;
343 @media print {
344 div#footer-badges { display: none; }
347 div#toc {
348 margin-bottom: 2.5em;
351 div#toctitle {
352 color: #527bbd;
353 font-family: sans-serif;
354 font-size: 1.1em;
355 font-weight: bold;
356 margin-top: 1.0em;
357 margin-bottom: 0.1em;
360 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
361 margin-top: 0;
362 margin-bottom: 0;
364 div.toclevel2 {
365 margin-left: 2em;
366 font-size: 0.9em;
368 div.toclevel3 {
369 margin-left: 4em;
370 font-size: 0.9em;
372 div.toclevel4 {
373 margin-left: 6em;
374 font-size: 0.9em;
376 /* Overrides for manpage documents */
377 h1 {
378 padding-top: 0.5em;
379 padding-bottom: 0.5em;
380 border-top: 2px solid silver;
381 border-bottom: 2px solid silver;
383 h2 {
384 border-style: none;
386 div.sectionbody {
387 margin-left: 5%;
390 @media print {
391 div#toc { display: none; }
394 /* Workarounds for IE6's broken and incomplete CSS2. */
396 div.sidebar-content {
397 background: #ffffee;
398 border: 1px solid silver;
399 padding: 0.5em;
401 div.sidebar-title, div.image-title {
402 color: #527bbd;
403 font-family: sans-serif;
404 font-weight: bold;
405 margin-top: 0.0em;
406 margin-bottom: 0.5em;
409 div.listingblock div.content {
410 border: 1px solid silver;
411 background: #f4f4f4;
412 padding: 0.5em;
415 div.quoteblock-attribution {
416 padding-top: 0.5em;
417 text-align: right;
420 div.verseblock-content {
421 white-space: pre;
423 div.verseblock-attribution {
424 padding-top: 0.75em;
425 text-align: left;
428 div.exampleblock-content {
429 border-left: 3px solid #dddddd;
430 padding-left: 0.5em;
433 /* IE6 sets dynamically generated links as visited. */
434 div#toc a:visited { color: blue; }
435 </style>
436 <script type="text/javascript">
437 /*<![CDATA[*/
438 window.onload = function(){asciidoc.footnotes();}
439 var asciidoc = { // Namespace.
441 /////////////////////////////////////////////////////////////////////
442 // Table Of Contents generator
443 /////////////////////////////////////////////////////////////////////
445 /* Author: Mihai Bazon, September 2002
446 * http://students.infoiasi.ro/~mishoo
448 * Table Of Content generator
449 * Version: 0.4
451 * Feel free to use this script under the terms of the GNU General Public
452 * License, as long as you do not remove or alter this notice.
455 /* modified by Troy D. Hanson, September 2006. License: GPL */
456 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
458 // toclevels = 1..4.
459 toc: function (toclevels) {
461 function getText(el) {
462 var text = "";
463 for (var i = el.firstChild; i != null; i = i.nextSibling) {
464 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
465 text += i.data;
466 else if (i.firstChild != null)
467 text += getText(i);
469 return text;
472 function TocEntry(el, text, toclevel) {
473 this.element = el;
474 this.text = text;
475 this.toclevel = toclevel;
478 function tocEntries(el, toclevels) {
479 var result = new Array;
480 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
481 // Function that scans the DOM tree for header elements (the DOM2
482 // nodeIterator API would be a better technique but not supported by all
483 // browsers).
484 var iterate = function (el) {
485 for (var i = el.firstChild; i != null; i = i.nextSibling) {
486 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
487 var mo = re.exec(i.tagName);
488 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
489 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
491 iterate(i);
495 iterate(el);
496 return result;
499 var toc = document.getElementById("toc");
500 var entries = tocEntries(document.getElementById("content"), toclevels);
501 for (var i = 0; i < entries.length; ++i) {
502 var entry = entries[i];
503 if (entry.element.id == "")
504 entry.element.id = "_toc_" + i;
505 var a = document.createElement("a");
506 a.href = "#" + entry.element.id;
507 a.appendChild(document.createTextNode(entry.text));
508 var div = document.createElement("div");
509 div.appendChild(a);
510 div.className = "toclevel" + entry.toclevel;
511 toc.appendChild(div);
513 if (entries.length == 0)
514 toc.parentNode.removeChild(toc);
518 /////////////////////////////////////////////////////////////////////
519 // Footnotes generator
520 /////////////////////////////////////////////////////////////////////
522 /* Based on footnote generation code from:
523 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
526 footnotes: function () {
527 var cont = document.getElementById("content");
528 var noteholder = document.getElementById("footnotes");
529 var spans = cont.getElementsByTagName("span");
530 var refs = {};
531 var n = 0;
532 for (i=0; i<spans.length; i++) {
533 if (spans[i].className == "footnote") {
534 n++;
535 // Use [\s\S] in place of . so multi-line matches work.
536 // Because JavaScript has no s (dotall) regex flag.
537 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
538 noteholder.innerHTML +=
539 "<div class='footnote' id='_footnote_" + n + "'>" +
540 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
541 n + "</a>. " + note + "</div>";
542 spans[i].innerHTML =
543 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
544 "' title='View footnote' class='footnote'>" + n + "</a>]";
545 var id =spans[i].getAttribute("id");
546 if (id != null) refs["#"+id] = n;
549 if (n == 0)
550 noteholder.parentNode.removeChild(noteholder);
551 else {
552 // Process footnoterefs.
553 for (i=0; i<spans.length; i++) {
554 if (spans[i].className == "footnoteref") {
555 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
556 href = href.match(/#.*/)[0]; // Because IE return full URL.
557 n = refs[href];
558 spans[i].innerHTML =
559 "[<a href='#_footnote_" + n +
560 "' title='View footnote' class='footnote'>" + n + "</a>]";
567 /*]]>*/
568 </script>
569 </head>
570 <body>
571 <div id="header">
572 <h1>
573 git-rebase(1) Manual Page
574 </h1>
575 <h2>NAME</h2>
576 <div class="sectionbody">
577 <p>git-rebase -
578 Forward-port local commits to the updated upstream head
579 </p>
580 </div>
581 </div>
582 <div id="content">
583 <h2 id="_synopsis">SYNOPSIS</h2>
584 <div class="sectionbody">
585 <div class="verseblock">
586 <div class="verseblock-content"><em>git rebase</em> [-i | --interactive] [options] [--onto &lt;newbase&gt;]
587 [&lt;upstream&gt;] [&lt;branch&gt;]
588 <em>git rebase</em> [-i | --interactive] [options] --onto &lt;newbase&gt;
589 --root [&lt;branch&gt;]
590 <em>git rebase</em> --continue | --skip | --abort</div>
591 <div class="verseblock-attribution">
592 </div></div>
593 </div>
594 <h2 id="_description">DESCRIPTION</h2>
595 <div class="sectionbody">
596 <div class="paragraph"><p>If &lt;branch&gt; is specified, <em>git rebase</em> will perform an automatic
597 <tt>git checkout &lt;branch&gt;</tt> before doing anything else. Otherwise
598 it remains on the current branch.</p></div>
599 <div class="paragraph"><p>If &lt;upstream&gt; is not specified, the upstream configured in
600 branch.&lt;name&gt;.remote and branch.&lt;name&gt;.merge options will be used; see
601 <a href="git-config.html">git-config(1)</a> for details. If you are currently not on any
602 branch or if the current branch does not have a configured upstream,
603 the rebase will abort.</p></div>
604 <div class="paragraph"><p>All changes made by commits in the current branch but that are not
605 in &lt;upstream&gt; are saved to a temporary area. This is the same set
606 of commits that would be shown by <tt>git log &lt;upstream&gt;..HEAD</tt> (or
607 <tt>git log HEAD</tt>, if --root is specified).</p></div>
608 <div class="paragraph"><p>The current branch is reset to &lt;upstream&gt;, or &lt;newbase&gt; if the
609 --onto option was supplied. This has the exact same effect as
610 <tt>git reset --hard &lt;upstream&gt;</tt> (or &lt;newbase&gt;). ORIG_HEAD is set
611 to point at the tip of the branch before the reset.</p></div>
612 <div class="paragraph"><p>The commits that were previously saved into the temporary area are
613 then reapplied to the current branch, one by one, in order. Note that
614 any commits in HEAD which introduce the same textual changes as a commit
615 in HEAD..&lt;upstream&gt; are omitted (i.e., a patch already accepted upstream
616 with a different commit message or timestamp will be skipped).</p></div>
617 <div class="paragraph"><p>It is possible that a merge failure will prevent this process from being
618 completely automatic. You will have to resolve any such merge failure
619 and run <tt>git rebase --continue</tt>. Another option is to bypass the commit
620 that caused the merge failure with <tt>git rebase --skip</tt>. To check out the
621 original &lt;branch&gt; and remove the .git/rebase-apply working files, use the
622 command <tt>git rebase --abort</tt> instead.</p></div>
623 <div class="paragraph"><p>Assume the following history exists and the current branch is "topic":</p></div>
624 <div class="listingblock">
625 <div class="content">
626 <pre><tt> A---B---C topic
628 D---E---F---G master</tt></pre>
629 </div></div>
630 <div class="paragraph"><p>From this point, the result of either of the following commands:</p></div>
631 <div class="literalblock">
632 <div class="content">
633 <pre><tt>git rebase master
634 git rebase master topic</tt></pre>
635 </div></div>
636 <div class="paragraph"><p>would be:</p></div>
637 <div class="listingblock">
638 <div class="content">
639 <pre><tt> A'--B'--C' topic
641 D---E---F---G master</tt></pre>
642 </div></div>
643 <div class="paragraph"><p><strong>NOTE:</strong> The latter form is just a short-hand of <tt>git checkout topic</tt>
644 followed by <tt>git rebase master</tt>. When rebase exits <tt>topic</tt> will
645 remain the checked-out branch.</p></div>
646 <div class="paragraph"><p>If the upstream branch already contains a change you have made (e.g.,
647 because you mailed a patch which was applied upstream), then that commit
648 will be skipped. For example, running &#8216;git rebase master` on the
649 following history (in which A&#8217; and A introduce the same set of changes,
650 but have different committer information):</p></div>
651 <div class="listingblock">
652 <div class="content">
653 <pre><tt> A---B---C topic
655 D---E---A'---F master</tt></pre>
656 </div></div>
657 <div class="paragraph"><p>will result in:</p></div>
658 <div class="listingblock">
659 <div class="content">
660 <pre><tt> B'---C' topic
662 D---E---A'---F master</tt></pre>
663 </div></div>
664 <div class="paragraph"><p>Here is how you would transplant a topic branch based on one
665 branch to another, to pretend that you forked the topic branch
666 from the latter branch, using <tt>rebase --onto</tt>.</p></div>
667 <div class="paragraph"><p>First let&#8217;s assume your <em>topic</em> is based on branch <em>next</em>.
668 For example, a feature developed in <em>topic</em> depends on some
669 functionality which is found in <em>next</em>.</p></div>
670 <div class="listingblock">
671 <div class="content">
672 <pre><tt> o---o---o---o---o master
674 o---o---o---o---o next
676 o---o---o topic</tt></pre>
677 </div></div>
678 <div class="paragraph"><p>We want to make <em>topic</em> forked from branch <em>master</em>; for example,
679 because the functionality on which <em>topic</em> depends was merged into the
680 more stable <em>master</em> branch. We want our tree to look like this:</p></div>
681 <div class="listingblock">
682 <div class="content">
683 <pre><tt> o---o---o---o---o master
685 | o'--o'--o' topic
687 o---o---o---o---o next</tt></pre>
688 </div></div>
689 <div class="paragraph"><p>We can get this using the following command:</p></div>
690 <div class="literalblock">
691 <div class="content">
692 <pre><tt>git rebase --onto master next topic</tt></pre>
693 </div></div>
694 <div class="paragraph"><p>Another example of --onto option is to rebase part of a
695 branch. If we have the following situation:</p></div>
696 <div class="listingblock">
697 <div class="content">
698 <pre><tt> H---I---J topicB
700 E---F---G topicA
702 A---B---C---D master</tt></pre>
703 </div></div>
704 <div class="paragraph"><p>then the command</p></div>
705 <div class="literalblock">
706 <div class="content">
707 <pre><tt>git rebase --onto master topicA topicB</tt></pre>
708 </div></div>
709 <div class="paragraph"><p>would result in:</p></div>
710 <div class="listingblock">
711 <div class="content">
712 <pre><tt> H'--I'--J' topicB
714 | E---F---G topicA
716 A---B---C---D master</tt></pre>
717 </div></div>
718 <div class="paragraph"><p>This is useful when topicB does not depend on topicA.</p></div>
719 <div class="paragraph"><p>A range of commits could also be removed with rebase. If we have
720 the following situation:</p></div>
721 <div class="listingblock">
722 <div class="content">
723 <pre><tt> E---F---G---H---I---J topicA</tt></pre>
724 </div></div>
725 <div class="paragraph"><p>then the command</p></div>
726 <div class="literalblock">
727 <div class="content">
728 <pre><tt>git rebase --onto topicA~5 topicA~3 topicA</tt></pre>
729 </div></div>
730 <div class="paragraph"><p>would result in the removal of commits F and G:</p></div>
731 <div class="listingblock">
732 <div class="content">
733 <pre><tt> E---H'---I'---J' topicA</tt></pre>
734 </div></div>
735 <div class="paragraph"><p>This is useful if F and G were flawed in some way, or should not be
736 part of topicA. Note that the argument to --onto and the &lt;upstream&gt;
737 parameter can be any valid commit-ish.</p></div>
738 <div class="paragraph"><p>In case of conflict, <em>git rebase</em> will stop at the first problematic commit
739 and leave conflict markers in the tree. You can use <em>git diff</em> to locate
740 the markers (&lt;&lt;&lt;&lt;&lt;&lt;) and make edits to resolve the conflict. For each
741 file you edit, you need to tell git that the conflict has been resolved,
742 typically this would be done with</p></div>
743 <div class="literalblock">
744 <div class="content">
745 <pre><tt>git add &lt;filename&gt;</tt></pre>
746 </div></div>
747 <div class="paragraph"><p>After resolving the conflict manually and updating the index with the
748 desired resolution, you can continue the rebasing process with</p></div>
749 <div class="literalblock">
750 <div class="content">
751 <pre><tt>git rebase --continue</tt></pre>
752 </div></div>
753 <div class="paragraph"><p>Alternatively, you can undo the <em>git rebase</em> with</p></div>
754 <div class="literalblock">
755 <div class="content">
756 <pre><tt>git rebase --abort</tt></pre>
757 </div></div>
758 </div>
759 <h2 id="_configuration">CONFIGURATION</h2>
760 <div class="sectionbody">
761 <div class="dlist"><dl>
762 <dt class="hdlist1">
763 rebase.stat
764 </dt>
765 <dd>
767 Whether to show a diffstat of what changed upstream since the last
768 rebase. False by default.
769 </p>
770 </dd>
771 <dt class="hdlist1">
772 rebase.autosquash
773 </dt>
774 <dd>
776 If set to true enable <em>--autosquash</em> option by default.
777 </p>
778 </dd>
779 </dl></div>
780 </div>
781 <h2 id="_options">OPTIONS</h2>
782 <div class="sectionbody">
783 <div class="dlist"><dl>
784 <dt class="hdlist1">
785 &lt;newbase&gt;
786 </dt>
787 <dd>
789 Starting point at which to create the new commits. If the
790 --onto option is not specified, the starting point is
791 &lt;upstream&gt;. May be any valid commit, and not just an
792 existing branch name.
793 </p>
794 <div class="paragraph"><p>As a special case, you may use "A...B" as a shortcut for the
795 merge base of A and B if there is exactly one merge base. You can
796 leave out at most one of A and B, in which case it defaults to HEAD.</p></div>
797 </dd>
798 <dt class="hdlist1">
799 &lt;upstream&gt;
800 </dt>
801 <dd>
803 Upstream branch to compare against. May be any valid commit,
804 not just an existing branch name. Defaults to the configured
805 upstream for the current branch.
806 </p>
807 </dd>
808 <dt class="hdlist1">
809 &lt;branch&gt;
810 </dt>
811 <dd>
813 Working branch; defaults to HEAD.
814 </p>
815 </dd>
816 <dt class="hdlist1">
817 --continue
818 </dt>
819 <dd>
821 Restart the rebasing process after having resolved a merge conflict.
822 </p>
823 </dd>
824 <dt class="hdlist1">
825 --abort
826 </dt>
827 <dd>
829 Abort the rebase operation and reset HEAD to the original
830 branch. If &lt;branch&gt; was provided when the rebase operation was
831 started, then HEAD will be reset to &lt;branch&gt;. Otherwise HEAD
832 will be reset to where it was when the rebase operation was
833 started.
834 </p>
835 </dd>
836 <dt class="hdlist1">
837 --skip
838 </dt>
839 <dd>
841 Restart the rebasing process by skipping the current patch.
842 </p>
843 </dd>
844 <dt class="hdlist1">
846 </dt>
847 <dt class="hdlist1">
848 --merge
849 </dt>
850 <dd>
852 Use merging strategies to rebase. When the recursive (default) merge
853 strategy is used, this allows rebase to be aware of renames on the
854 upstream side.
855 </p>
856 <div class="paragraph"><p>Note that a rebase merge works by replaying each commit from the working
857 branch on top of the &lt;upstream&gt; branch. Because of this, when a merge
858 conflict happens, the side reported as <em>ours</em> is the so-far rebased
859 series, starting with &lt;upstream&gt;, and <em>theirs</em> is the working branch. In
860 other words, the sides are swapped.</p></div>
861 </dd>
862 <dt class="hdlist1">
863 -s &lt;strategy&gt;
864 </dt>
865 <dt class="hdlist1">
866 --strategy=&lt;strategy&gt;
867 </dt>
868 <dd>
870 Use the given merge strategy.
871 If there is no <tt>-s</tt> option <em>git merge-recursive</em> is used
872 instead. This implies --merge.
873 </p>
874 <div class="paragraph"><p>Because <em>git rebase</em> replays each commit from the working branch
875 on top of the &lt;upstream&gt; branch using the given strategy, using
876 the <em>ours</em> strategy simply discards all patches from the &lt;branch&gt;,
877 which makes little sense.</p></div>
878 </dd>
879 <dt class="hdlist1">
880 -X &lt;strategy-option&gt;
881 </dt>
882 <dt class="hdlist1">
883 --strategy-option=&lt;strategy-option&gt;
884 </dt>
885 <dd>
887 Pass the &lt;strategy-option&gt; through to the merge strategy.
888 This implies <tt>--merge</tt> and, if no strategy has been
889 specified, <tt>-s recursive</tt>. Note the reversal of <em>ours</em> and
890 <em>theirs</em> as noted in above for the <tt>-m</tt> option.
891 </p>
892 </dd>
893 <dt class="hdlist1">
895 </dt>
896 <dt class="hdlist1">
897 --quiet
898 </dt>
899 <dd>
901 Be quiet. Implies --no-stat.
902 </p>
903 </dd>
904 <dt class="hdlist1">
906 </dt>
907 <dt class="hdlist1">
908 --verbose
909 </dt>
910 <dd>
912 Be verbose. Implies --stat.
913 </p>
914 </dd>
915 <dt class="hdlist1">
916 --stat
917 </dt>
918 <dd>
920 Show a diffstat of what changed upstream since the last rebase. The
921 diffstat is also controlled by the configuration option rebase.stat.
922 </p>
923 </dd>
924 <dt class="hdlist1">
926 </dt>
927 <dt class="hdlist1">
928 --no-stat
929 </dt>
930 <dd>
932 Do not show a diffstat as part of the rebase process.
933 </p>
934 </dd>
935 <dt class="hdlist1">
936 --no-verify
937 </dt>
938 <dd>
940 This option bypasses the pre-rebase hook. See also <a href="githooks.html">githooks(5)</a>.
941 </p>
942 </dd>
943 <dt class="hdlist1">
944 --verify
945 </dt>
946 <dd>
948 Allows the pre-rebase hook to run, which is the default. This option can
949 be used to override --no-verify. See also <a href="githooks.html">githooks(5)</a>.
950 </p>
951 </dd>
952 <dt class="hdlist1">
953 -C&lt;n&gt;
954 </dt>
955 <dd>
957 Ensure at least &lt;n&gt; lines of surrounding context match before
958 and after each change. When fewer lines of surrounding
959 context exist they all must match. By default no context is
960 ever ignored.
961 </p>
962 </dd>
963 <dt class="hdlist1">
965 </dt>
966 <dt class="hdlist1">
967 --force-rebase
968 </dt>
969 <dd>
971 Force the rebase even if the current branch is a descendant
972 of the commit you are rebasing onto. Normally non-interactive rebase will
973 exit with the message "Current branch is up to date" in such a
974 situation.
975 Incompatible with the --interactive option.
976 </p>
977 <div class="paragraph"><p>You may find this (or --no-ff with an interactive rebase) helpful after
978 reverting a topic branch merge, as this option recreates the topic branch with
979 fresh commits so it can be remerged successfully without needing to "revert
980 the reversion" (see the
981 <a href="howto/revert-a-faulty-merge.txt">revert-a-faulty-merge How-To</a> for details).</p></div>
982 </dd>
983 <dt class="hdlist1">
984 --ignore-whitespace
985 </dt>
986 <dt class="hdlist1">
987 --whitespace=&lt;option&gt;
988 </dt>
989 <dd>
991 These flag are passed to the <em>git apply</em> program
992 (see <a href="git-apply.html">git-apply(1)</a>) that applies the patch.
993 Incompatible with the --interactive option.
994 </p>
995 </dd>
996 <dt class="hdlist1">
997 --committer-date-is-author-date
998 </dt>
999 <dt class="hdlist1">
1000 --ignore-date
1001 </dt>
1002 <dd>
1004 These flags are passed to <em>git am</em> to easily change the dates
1005 of the rebased commits (see <a href="git-am.html">git-am(1)</a>).
1006 Incompatible with the --interactive option.
1007 </p>
1008 </dd>
1009 <dt class="hdlist1">
1011 </dt>
1012 <dt class="hdlist1">
1013 --interactive
1014 </dt>
1015 <dd>
1017 Make a list of the commits which are about to be rebased. Let the
1018 user edit that list before rebasing. This mode can also be used to
1019 split commits (see SPLITTING COMMITS below).
1020 </p>
1021 </dd>
1022 <dt class="hdlist1">
1024 </dt>
1025 <dt class="hdlist1">
1026 --preserve-merges
1027 </dt>
1028 <dd>
1030 Instead of ignoring merges, try to recreate them.
1031 </p>
1032 <div class="paragraph"><p>This uses the <tt>--interactive</tt> machinery internally, but combining it
1033 with the <tt>--interactive</tt> option explicitly is generally not a good
1034 idea unless you know what you are doing (see BUGS below).</p></div>
1035 </dd>
1036 <dt class="hdlist1">
1037 --root
1038 </dt>
1039 <dd>
1041 Rebase all commits reachable from &lt;branch&gt;, instead of
1042 limiting them with an &lt;upstream&gt;. This allows you to rebase
1043 the root commit(s) on a branch. Must be used with --onto, and
1044 will skip changes already contained in &lt;newbase&gt; (instead of
1045 &lt;upstream&gt;). When used together with --preserve-merges, <em>all</em>
1046 root commits will be rewritten to have &lt;newbase&gt; as parent
1047 instead.
1048 </p>
1049 </dd>
1050 <dt class="hdlist1">
1051 --autosquash
1052 </dt>
1053 <dt class="hdlist1">
1054 --no-autosquash
1055 </dt>
1056 <dd>
1058 When the commit log message begins with "squash! &#8230;" (or
1059 "fixup! &#8230;"), and there is a commit whose title begins with
1060 the same &#8230;, automatically modify the todo list of rebase -i
1061 so that the commit marked for squashing comes right after the
1062 commit to be modified, and change the action of the moved
1063 commit from <tt>pick</tt> to <tt>squash</tt> (or <tt>fixup</tt>).
1064 </p>
1065 <div class="paragraph"><p>This option is only valid when the <em>--interactive</em> option is used.</p></div>
1066 <div class="paragraph"><p>If the <em>--autosquash</em> option is enabled by default using the
1067 configuration variable <tt>rebase.autosquash</tt>, this option can be
1068 used to override and disable this setting.</p></div>
1069 </dd>
1070 <dt class="hdlist1">
1071 --no-ff
1072 </dt>
1073 <dd>
1075 With --interactive, cherry-pick all rebased commits instead of
1076 fast-forwarding over the unchanged ones. This ensures that the
1077 entire history of the rebased branch is composed of new commits.
1078 </p>
1079 <div class="paragraph"><p>Without --interactive, this is a synonym for --force-rebase.</p></div>
1080 <div class="paragraph"><p>You may find this helpful after reverting a topic branch merge, as this option
1081 recreates the topic branch with fresh commits so it can be remerged
1082 successfully without needing to "revert the reversion" (see the
1083 <a href="howto/revert-a-faulty-merge.txt">revert-a-faulty-merge How-To</a> for details).</p></div>
1084 </dd>
1085 </dl></div>
1086 </div>
1087 <h2 id="_merge_strategies">MERGE STRATEGIES</h2>
1088 <div class="sectionbody">
1089 <div class="paragraph"><p>The merge mechanism (<em>git-merge</em> and <em>git-pull</em> commands) allows the
1090 backend <em>merge strategies</em> to be chosen with <tt>-s</tt> option. Some strategies
1091 can also take their own options, which can be passed by giving <tt>-X&lt;option&gt;</tt>
1092 arguments to <em>git-merge</em> and/or <em>git-pull</em>.</p></div>
1093 <div class="dlist"><dl>
1094 <dt class="hdlist1">
1095 resolve
1096 </dt>
1097 <dd>
1099 This can only resolve two heads (i.e. the current branch
1100 and another branch you pulled from) using a 3-way merge
1101 algorithm. It tries to carefully detect criss-cross
1102 merge ambiguities and is considered generally safe and
1103 fast.
1104 </p>
1105 </dd>
1106 <dt class="hdlist1">
1107 recursive
1108 </dt>
1109 <dd>
1111 This can only resolve two heads using a 3-way merge
1112 algorithm. When there is more than one common
1113 ancestor that can be used for 3-way merge, it creates a
1114 merged tree of the common ancestors and uses that as
1115 the reference tree for the 3-way merge. This has been
1116 reported to result in fewer merge conflicts without
1117 causing mis-merges by tests done on actual merge commits
1118 taken from Linux 2.6 kernel development history.
1119 Additionally this can detect and handle merges involving
1120 renames. This is the default merge strategy when
1121 pulling or merging one branch.
1122 </p>
1123 <div class="paragraph"><p>The <em>recursive</em> strategy can take the following options:</p></div>
1124 <div class="dlist"><dl>
1125 <dt class="hdlist1">
1126 ours
1127 </dt>
1128 <dd>
1130 This option forces conflicting hunks to be auto-resolved cleanly by
1131 favoring <em>our</em> version. Changes from the other tree that do not
1132 conflict with our side are reflected to the merge result.
1133 </p>
1134 <div class="paragraph"><p>This should not be confused with the <em>ours</em> merge strategy, which does not
1135 even look at what the other tree contains at all. It discards everything
1136 the other tree did, declaring <em>our</em> history contains all that happened in it.</p></div>
1137 </dd>
1138 <dt class="hdlist1">
1139 theirs
1140 </dt>
1141 <dd>
1143 This is opposite of <em>ours</em>.
1144 </p>
1145 </dd>
1146 <dt class="hdlist1">
1147 patience
1148 </dt>
1149 <dd>
1151 With this option, <em>merge-recursive</em> spends a little extra time
1152 to avoid mismerges that sometimes occur due to unimportant
1153 matching lines (e.g., braces from distinct functions). Use
1154 this when the branches to be merged have diverged wildly.
1155 See also <a href="git-diff.html">git-diff(1)</a> <tt>--patience</tt>.
1156 </p>
1157 </dd>
1158 <dt class="hdlist1">
1159 ignore-space-change
1160 </dt>
1161 <dt class="hdlist1">
1162 ignore-all-space
1163 </dt>
1164 <dt class="hdlist1">
1165 ignore-space-at-eol
1166 </dt>
1167 <dd>
1169 Treats lines with the indicated type of whitespace change as
1170 unchanged for the sake of a three-way merge. Whitespace
1171 changes mixed with other changes to a line are not ignored.
1172 See also <a href="git-diff.html">git-diff(1)</a> <tt>-b</tt>, <tt>-w</tt>, and
1173 <tt>--ignore-space-at-eol</tt>.
1174 </p>
1175 <div class="ulist"><ul>
1176 <li>
1178 If <em>their</em> version only introduces whitespace changes to a line,
1179 <em>our</em> version is used;
1180 </p>
1181 </li>
1182 <li>
1184 If <em>our</em> version introduces whitespace changes but <em>their</em>
1185 version includes a substantial change, <em>their</em> version is used;
1186 </p>
1187 </li>
1188 <li>
1190 Otherwise, the merge proceeds in the usual way.
1191 </p>
1192 </li>
1193 </ul></div>
1194 </dd>
1195 <dt class="hdlist1">
1196 renormalize
1197 </dt>
1198 <dd>
1200 This runs a virtual check-out and check-in of all three stages
1201 of a file when resolving a three-way merge. This option is
1202 meant to be used when merging branches with different clean
1203 filters or end-of-line normalization rules. See "Merging
1204 branches with differing checkin/checkout attributes" in
1205 <a href="gitattributes.html">gitattributes(5)</a> for details.
1206 </p>
1207 </dd>
1208 <dt class="hdlist1">
1209 no-renormalize
1210 </dt>
1211 <dd>
1213 Disables the <tt>renormalize</tt> option. This overrides the
1214 <tt>merge.renormalize</tt> configuration variable.
1215 </p>
1216 </dd>
1217 <dt class="hdlist1">
1218 rename-threshold=&lt;n&gt;
1219 </dt>
1220 <dd>
1222 Controls the similarity threshold used for rename detection.
1223 See also <a href="git-diff.html">git-diff(1)</a> <tt>-M</tt>.
1224 </p>
1225 </dd>
1226 <dt class="hdlist1">
1227 subtree[=&lt;path&gt;]
1228 </dt>
1229 <dd>
1231 This option is a more advanced form of <em>subtree</em> strategy, where
1232 the strategy makes a guess on how two trees must be shifted to
1233 match with each other when merging. Instead, the specified path
1234 is prefixed (or stripped from the beginning) to make the shape of
1235 two trees to match.
1236 </p>
1237 </dd>
1238 </dl></div>
1239 </dd>
1240 <dt class="hdlist1">
1241 octopus
1242 </dt>
1243 <dd>
1245 This resolves cases with more than two heads, but refuses to do
1246 a complex merge that needs manual resolution. It is
1247 primarily meant to be used for bundling topic branch
1248 heads together. This is the default merge strategy when
1249 pulling or merging more than one branch.
1250 </p>
1251 </dd>
1252 <dt class="hdlist1">
1253 ours
1254 </dt>
1255 <dd>
1257 This resolves any number of heads, but the resulting tree of the
1258 merge is always that of the current branch head, effectively
1259 ignoring all changes from all other branches. It is meant to
1260 be used to supersede old development history of side
1261 branches. Note that this is different from the -Xours option to
1262 the <em>recursive</em> merge strategy.
1263 </p>
1264 </dd>
1265 <dt class="hdlist1">
1266 subtree
1267 </dt>
1268 <dd>
1270 This is a modified recursive strategy. When merging trees A and
1271 B, if B corresponds to a subtree of A, B is first adjusted to
1272 match the tree structure of A, instead of reading the trees at
1273 the same level. This adjustment is also done to the common
1274 ancestor tree.
1275 </p>
1276 </dd>
1277 </dl></div>
1278 </div>
1279 <h2 id="_notes">NOTES</h2>
1280 <div class="sectionbody">
1281 <div class="paragraph"><p>You should understand the implications of using <em>git rebase</em> on a
1282 repository that you share. See also RECOVERING FROM UPSTREAM REBASE
1283 below.</p></div>
1284 <div class="paragraph"><p>When the git-rebase command is run, it will first execute a "pre-rebase"
1285 hook if one exists. You can use this hook to do sanity checks and
1286 reject the rebase if it isn&#8217;t appropriate. Please see the template
1287 pre-rebase hook script for an example.</p></div>
1288 <div class="paragraph"><p>Upon completion, &lt;branch&gt; will be the current branch.</p></div>
1289 </div>
1290 <h2 id="_interactive_mode">INTERACTIVE MODE</h2>
1291 <div class="sectionbody">
1292 <div class="paragraph"><p>Rebasing interactively means that you have a chance to edit the commits
1293 which are rebased. You can reorder the commits, and you can
1294 remove them (weeding out bad or otherwise unwanted patches).</p></div>
1295 <div class="paragraph"><p>The interactive mode is meant for this type of workflow:</p></div>
1296 <div class="olist arabic"><ol class="arabic">
1297 <li>
1299 have a wonderful idea
1300 </p>
1301 </li>
1302 <li>
1304 hack on the code
1305 </p>
1306 </li>
1307 <li>
1309 prepare a series for submission
1310 </p>
1311 </li>
1312 <li>
1314 submit
1315 </p>
1316 </li>
1317 </ol></div>
1318 <div class="paragraph"><p>where point 2. consists of several instances of</p></div>
1319 <div class="olist loweralpha"><ol class="loweralpha">
1320 <li>
1322 regular use
1323 </p>
1324 <div class="olist arabic"><ol class="arabic">
1325 <li>
1327 finish something worthy of a commit
1328 </p>
1329 </li>
1330 <li>
1332 commit
1333 </p>
1334 </li>
1335 </ol></div>
1336 </li>
1337 <li>
1339 independent fixup
1340 </p>
1341 <div class="olist arabic"><ol class="arabic">
1342 <li>
1344 realize that something does not work
1345 </p>
1346 </li>
1347 <li>
1349 fix that
1350 </p>
1351 </li>
1352 <li>
1354 commit it
1355 </p>
1356 </li>
1357 </ol></div>
1358 </li>
1359 </ol></div>
1360 <div class="paragraph"><p>Sometimes the thing fixed in b.2. cannot be amended to the not-quite
1361 perfect commit it fixes, because that commit is buried deeply in a
1362 patch series. That is exactly what interactive rebase is for: use it
1363 after plenty of "a"s and "b"s, by rearranging and editing
1364 commits, and squashing multiple commits into one.</p></div>
1365 <div class="paragraph"><p>Start it with the last commit you want to retain as-is:</p></div>
1366 <div class="literalblock">
1367 <div class="content">
1368 <pre><tt>git rebase -i &lt;after-this-commit&gt;</tt></pre>
1369 </div></div>
1370 <div class="paragraph"><p>An editor will be fired up with all the commits in your current branch
1371 (ignoring merge commits), which come after the given commit. You can
1372 reorder the commits in this list to your heart&#8217;s content, and you can
1373 remove them. The list looks more or less like this:</p></div>
1374 <div class="listingblock">
1375 <div class="content">
1376 <pre><tt>pick deadbee The oneline of this commit
1377 pick fa1afe1 The oneline of the next commit
1378 ...</tt></pre>
1379 </div></div>
1380 <div class="paragraph"><p>The oneline descriptions are purely for your pleasure; <em>git rebase</em> will
1381 not look at them but at the commit names ("deadbee" and "fa1afe1" in this
1382 example), so do not delete or edit the names.</p></div>
1383 <div class="paragraph"><p>By replacing the command "pick" with the command "edit", you can tell
1384 <em>git rebase</em> to stop after applying that commit, so that you can edit
1385 the files and/or the commit message, amend the commit, and continue
1386 rebasing.</p></div>
1387 <div class="paragraph"><p>If you just want to edit the commit message for a commit, replace the
1388 command "pick" with the command "reword".</p></div>
1389 <div class="paragraph"><p>If you want to fold two or more commits into one, replace the command
1390 "pick" for the second and subsequent commits with "squash" or "fixup".
1391 If the commits had different authors, the folded commit will be
1392 attributed to the author of the first commit. The suggested commit
1393 message for the folded commit is the concatenation of the commit
1394 messages of the first commit and of those with the "squash" command,
1395 but omits the commit messages of commits with the "fixup" command.</p></div>
1396 <div class="paragraph"><p><em>git rebase</em> will stop when "pick" has been replaced with "edit" or
1397 when a command fails due to merge errors. When you are done editing
1398 and/or resolving conflicts you can continue with <tt>git rebase --continue</tt>.</p></div>
1399 <div class="paragraph"><p>For example, if you want to reorder the last 5 commits, such that what
1400 was HEAD~4 becomes the new HEAD. To achieve that, you would call
1401 <em>git rebase</em> like this:</p></div>
1402 <div class="listingblock">
1403 <div class="content">
1404 <pre><tt>$ git rebase -i HEAD~5</tt></pre>
1405 </div></div>
1406 <div class="paragraph"><p>And move the first patch to the end of the list.</p></div>
1407 <div class="paragraph"><p>You might want to preserve merges, if you have a history like this:</p></div>
1408 <div class="listingblock">
1409 <div class="content">
1410 <pre><tt> X
1412 A---M---B
1414 ---o---O---P---Q</tt></pre>
1415 </div></div>
1416 <div class="paragraph"><p>Suppose you want to rebase the side branch starting at "A" to "Q". Make
1417 sure that the current HEAD is "B", and call</p></div>
1418 <div class="listingblock">
1419 <div class="content">
1420 <pre><tt>$ git rebase -i -p --onto Q O</tt></pre>
1421 </div></div>
1422 <div class="paragraph"><p>Reordering and editing commits usually creates untested intermediate
1423 steps. You may want to check that your history editing did not break
1424 anything by running a test, or at least recompiling at intermediate
1425 points in history by using the "exec" command (shortcut "x"). You may
1426 do so by creating a todo list like this one:</p></div>
1427 <div class="listingblock">
1428 <div class="content">
1429 <pre><tt>pick deadbee Implement feature XXX
1430 fixup f1a5c00 Fix to feature XXX
1431 exec make
1432 pick c0ffeee The oneline of the next commit
1433 edit deadbab The oneline of the commit after
1434 exec cd subdir; make test
1435 ...</tt></pre>
1436 </div></div>
1437 <div class="paragraph"><p>The interactive rebase will stop when a command fails (i.e. exits with
1438 non-0 status) to give you an opportunity to fix the problem. You can
1439 continue with <tt>git rebase --continue</tt>.</p></div>
1440 <div class="paragraph"><p>The "exec" command launches the command in a shell (the one specified
1441 in <tt>$SHELL</tt>, or the default shell if <tt>$SHELL</tt> is not set), so you can
1442 use shell features (like "cd", "&gt;", ";" &#8230;). The command is run from
1443 the root of the working tree.</p></div>
1444 </div>
1445 <h2 id="_splitting_commits">SPLITTING COMMITS</h2>
1446 <div class="sectionbody">
1447 <div class="paragraph"><p>In interactive mode, you can mark commits with the action "edit". However,
1448 this does not necessarily mean that <em>git rebase</em> expects the result of this
1449 edit to be exactly one commit. Indeed, you can undo the commit, or you can
1450 add other commits. This can be used to split a commit into two:</p></div>
1451 <div class="ulist"><ul>
1452 <li>
1454 Start an interactive rebase with <tt>git rebase -i &lt;commit&gt;^</tt>, where
1455 &lt;commit&gt; is the commit you want to split. In fact, any commit range
1456 will do, as long as it contains that commit.
1457 </p>
1458 </li>
1459 <li>
1461 Mark the commit you want to split with the action "edit".
1462 </p>
1463 </li>
1464 <li>
1466 When it comes to editing that commit, execute <tt>git reset HEAD^</tt>. The
1467 effect is that the HEAD is rewound by one, and the index follows suit.
1468 However, the working tree stays the same.
1469 </p>
1470 </li>
1471 <li>
1473 Now add the changes to the index that you want to have in the first
1474 commit. You can use <tt>git add</tt> (possibly interactively) or
1475 <em>git gui</em> (or both) to do that.
1476 </p>
1477 </li>
1478 <li>
1480 Commit the now-current index with whatever commit message is appropriate
1481 now.
1482 </p>
1483 </li>
1484 <li>
1486 Repeat the last two steps until your working tree is clean.
1487 </p>
1488 </li>
1489 <li>
1491 Continue the rebase with <tt>git rebase --continue</tt>.
1492 </p>
1493 </li>
1494 </ul></div>
1495 <div class="paragraph"><p>If you are not absolutely sure that the intermediate revisions are
1496 consistent (they compile, pass the testsuite, etc.) you should use
1497 <em>git stash</em> to stash away the not-yet-committed changes
1498 after each commit, test, and amend the commit if fixes are necessary.</p></div>
1499 </div>
1500 <h2 id="_recovering_from_upstream_rebase">RECOVERING FROM UPSTREAM REBASE</h2>
1501 <div class="sectionbody">
1502 <div class="paragraph"><p>Rebasing (or any other form of rewriting) a branch that others have
1503 based work on is a bad idea: anyone downstream of it is forced to
1504 manually fix their history. This section explains how to do the fix
1505 from the downstream&#8217;s point of view. The real fix, however, would be
1506 to avoid rebasing the upstream in the first place.</p></div>
1507 <div class="paragraph"><p>To illustrate, suppose you are in a situation where someone develops a
1508 <em>subsystem</em> branch, and you are working on a <em>topic</em> that is dependent
1509 on this <em>subsystem</em>. You might end up with a history like the
1510 following:</p></div>
1511 <div class="listingblock">
1512 <div class="content">
1513 <pre><tt> o---o---o---o---o---o---o---o---o master
1515 o---o---o---o---o subsystem
1517 *---*---* topic</tt></pre>
1518 </div></div>
1519 <div class="paragraph"><p>If <em>subsystem</em> is rebased against <em>master</em>, the following happens:</p></div>
1520 <div class="listingblock">
1521 <div class="content">
1522 <pre><tt> o---o---o---o---o---o---o---o master
1524 o---o---o---o---o o'--o'--o'--o'--o' subsystem
1526 *---*---* topic</tt></pre>
1527 </div></div>
1528 <div class="paragraph"><p>If you now continue development as usual, and eventually merge <em>topic</em>
1529 to <em>subsystem</em>, the commits from <em>subsystem</em> will remain duplicated forever:</p></div>
1530 <div class="listingblock">
1531 <div class="content">
1532 <pre><tt> o---o---o---o---o---o---o---o master
1534 o---o---o---o---o o'--o'--o'--o'--o'--M subsystem
1536 *---*---*-..........-*--* topic</tt></pre>
1537 </div></div>
1538 <div class="paragraph"><p>Such duplicates are generally frowned upon because they clutter up
1539 history, making it harder to follow. To clean things up, you need to
1540 transplant the commits on <em>topic</em> to the new <em>subsystem</em> tip, i.e.,
1541 rebase <em>topic</em>. This becomes a ripple effect: anyone downstream from
1542 <em>topic</em> is forced to rebase too, and so on!</p></div>
1543 <div class="paragraph"><p>There are two kinds of fixes, discussed in the following subsections:</p></div>
1544 <div class="dlist"><dl>
1545 <dt class="hdlist1">
1546 Easy case: The changes are literally the same.
1547 </dt>
1548 <dd>
1550 This happens if the <em>subsystem</em> rebase was a simple rebase and
1551 had no conflicts.
1552 </p>
1553 </dd>
1554 <dt class="hdlist1">
1555 Hard case: The changes are not the same.
1556 </dt>
1557 <dd>
1559 This happens if the <em>subsystem</em> rebase had conflicts, or used
1560 <tt>--interactive</tt> to omit, edit, squash, or fixup commits; or
1561 if the upstream used one of <tt>commit --amend</tt>, <tt>reset</tt>, or
1562 <tt>filter-branch</tt>.
1563 </p>
1564 </dd>
1565 </dl></div>
1566 <h3 id="_the_easy_case">The easy case</h3><div style="clear:left"></div>
1567 <div class="paragraph"><p>Only works if the changes (patch IDs based on the diff contents) on
1568 <em>subsystem</em> are literally the same before and after the rebase
1569 <em>subsystem</em> did.</p></div>
1570 <div class="paragraph"><p>In that case, the fix is easy because <em>git rebase</em> knows to skip
1571 changes that are already present in the new upstream. So if you say
1572 (assuming you&#8217;re on <em>topic</em>)</p></div>
1573 <div class="listingblock">
1574 <div class="content">
1575 <pre><tt> $ git rebase subsystem</tt></pre>
1576 </div></div>
1577 <div class="paragraph"><p>you will end up with the fixed history</p></div>
1578 <div class="listingblock">
1579 <div class="content">
1580 <pre><tt> o---o---o---o---o---o---o---o master
1582 o'--o'--o'--o'--o' subsystem
1584 *---*---* topic</tt></pre>
1585 </div></div>
1586 <h3 id="_the_hard_case">The hard case</h3><div style="clear:left"></div>
1587 <div class="paragraph"><p>Things get more complicated if the <em>subsystem</em> changes do not exactly
1588 correspond to the ones before the rebase.</p></div>
1589 <div class="admonitionblock">
1590 <table><tr>
1591 <td class="icon">
1592 <div class="title">Note</div>
1593 </td>
1594 <td class="content">While an "easy case recovery" sometimes appears to be successful
1595 even in the hard case, it may have unintended consequences. For
1596 example, a commit that was removed via <tt>git rebase
1597 --interactive</tt> will be <strong>resurrected</strong>!</td>
1598 </tr></table>
1599 </div>
1600 <div class="paragraph"><p>The idea is to manually tell <em>git rebase</em> "where the old <em>subsystem</em>
1601 ended and your <em>topic</em> began", that is, what the old merge-base
1602 between them was. You will have to find a way to name the last commit
1603 of the old <em>subsystem</em>, for example:</p></div>
1604 <div class="ulist"><ul>
1605 <li>
1607 With the <em>subsystem</em> reflog: after <em>git fetch</em>, the old tip of
1608 <em>subsystem</em> is at <tt>subsystem@{1}</tt>. Subsequent fetches will
1609 increase the number. (See <a href="git-reflog.html">git-reflog(1)</a>.)
1610 </p>
1611 </li>
1612 <li>
1614 Relative to the tip of <em>topic</em>: knowing that your <em>topic</em> has three
1615 commits, the old tip of <em>subsystem</em> must be <tt>topic~3</tt>.
1616 </p>
1617 </li>
1618 </ul></div>
1619 <div class="paragraph"><p>You can then transplant the old <tt>subsystem..topic</tt> to the new tip by
1620 saying (for the reflog case, and assuming you are on <em>topic</em> already):</p></div>
1621 <div class="listingblock">
1622 <div class="content">
1623 <pre><tt> $ git rebase --onto subsystem subsystem@{1}</tt></pre>
1624 </div></div>
1625 <div class="paragraph"><p>The ripple effect of a "hard case" recovery is especially bad:
1626 <em>everyone</em> downstream from <em>topic</em> will now have to perform a "hard
1627 case" recovery too!</p></div>
1628 </div>
1629 <h2 id="_bugs">BUGS</h2>
1630 <div class="sectionbody">
1631 <div class="paragraph"><p>The todo list presented by <tt>--preserve-merges --interactive</tt> does not
1632 represent the topology of the revision graph. Editing commits and
1633 rewording their commit messages should work fine, but attempts to
1634 reorder commits tend to produce counterintuitive results.</p></div>
1635 <div class="paragraph"><p>For example, an attempt to rearrange</p></div>
1636 <div class="listingblock">
1637 <div class="content">
1638 <pre><tt>1 --- 2 --- 3 --- 4 --- 5</tt></pre>
1639 </div></div>
1640 <div class="paragraph"><p>to</p></div>
1641 <div class="listingblock">
1642 <div class="content">
1643 <pre><tt>1 --- 2 --- 4 --- 3 --- 5</tt></pre>
1644 </div></div>
1645 <div class="paragraph"><p>by moving the "pick 4" line will result in the following history:</p></div>
1646 <div class="listingblock">
1647 <div class="content">
1648 <pre><tt> 3
1650 1 --- 2 --- 4 --- 5</tt></pre>
1651 </div></div>
1652 </div>
1653 <h2 id="_git">GIT</h2>
1654 <div class="sectionbody">
1655 <div class="paragraph"><p>Part of the <a href="git.html">git(1)</a> suite</p></div>
1656 </div>
1657 </div>
1658 <div id="footnotes"><hr /></div>
1659 <div id="footer">
1660 <div id="footer-text">
1661 Last updated 2011-09-21 23:01:14 PDT
1662 </div>
1663 </div>
1664 </body>
1665 </html>