1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
6 <meta http-equiv=
"Content-Type" content=
"application/xhtml+xml; charset=UTF-8" />
7 <meta name=
"generator" content=
"AsciiDoc 10.2.0" />
8 <title>git-rebase(
1)
</title>
9 <style type=
"text/css">
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
14 font-family: Georgia,serif;
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
22 #author, #revnumber, #revdate, #revremark,
24 font-family: Arial,Helvetica,sans-serif;
28 margin:
1em
5%
1em
5%;
33 text-decoration: underline;
49 h1, h2, h3, h4, h5, h6 {
57 border-bottom:
2px solid silver;
77 border:
1px solid silver;
88 ul
> li { color: #aaa; }
89 ul
> li
> * { color: black; }
91 .monospaced, code, pre {
92 font-family:
"Courier New", Courier, monospace;
99 white-space: pre-wrap;
109 #revnumber, #revdate, #revremark {
114 border-top:
2px solid silver;
120 padding-bottom:
0.5em;
124 padding-bottom:
0.5em;
129 margin-bottom:
1.5em;
131 div.imageblock, div.exampleblock, div.verseblock,
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
133 div.admonitionblock {
135 margin-bottom:
1.5em;
137 div.admonitionblock {
139 margin-bottom:
2.0em;
144 div.content { /* Block element content. */
148 /* Block element titles. */
149 div.title, caption.title {
154 margin-bottom:
0.5em;
160 td div.title:first-child {
163 div.content div.title:first-child {
166 div.content + div.title {
170 div.sidebarblock
> div.content {
172 border:
1px solid #dddddd;
173 border-left:
4px solid #f0f0f0;
177 div.listingblock
> div.content {
178 border:
1px solid #dddddd;
179 border-left:
5px solid #f0f0f0;
184 div.quoteblock, div.verseblock {
188 border-left:
5px solid #f0f0f0;
192 div.quoteblock
> div.attribution {
197 div.verseblock
> pre.content {
198 font-family: inherit;
201 div.verseblock
> div.attribution {
205 /* DEPRECATED: Pre version
8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
210 div.admonitionblock .icon {
214 text-decoration: underline;
216 padding-right:
0.5em;
218 div.admonitionblock td.content {
220 border-left:
3px solid #dddddd;
223 div.exampleblock
> div.content {
224 border-left:
3px solid #dddddd;
228 div.imageblock div.content { padding-left:
0; }
229 span.image img { border-style: none; vertical-align: text-bottom; }
230 a.image:visited { color: white; }
234 margin-bottom:
0.8em;
247 list-style-position: outside;
250 list-style-type: decimal;
253 list-style-type: lower-alpha;
256 list-style-type: upper-alpha;
259 list-style-type: lower-roman;
262 list-style-type: upper-roman;
265 div.compact ul, div.compact ol,
266 div.compact p, div.compact p,
267 div.compact div, div.compact div {
269 margin-bottom:
0.1em;
281 margin-bottom:
0.8em;
284 padding-bottom:
15px;
286 dt.hdlist1.strong, td.hdlist1.strong {
292 padding-right:
0.8em;
298 div.hdlist.compact tr {
307 .footnote, .footnoteref {
311 span.footnote, span.footnoteref {
312 vertical-align: super;
316 margin:
20px
0 20px
0;
320 #footnotes div.footnote {
326 border-top:
1px solid silver;
335 padding-right:
0.5em;
336 padding-bottom:
0.3em;
344 #footer-badges { display: none; }
348 margin-bottom:
2.5em;
356 margin-bottom:
0.1em;
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
376 span.aqua { color: aqua; }
377 span.black { color: black; }
378 span.blue { color: blue; }
379 span.fuchsia { color: fuchsia; }
380 span.gray { color: gray; }
381 span.green { color: green; }
382 span.lime { color: lime; }
383 span.maroon { color: maroon; }
384 span.navy { color: navy; }
385 span.olive { color: olive; }
386 span.purple { color: purple; }
387 span.red { color: red; }
388 span.silver { color: silver; }
389 span.teal { color: teal; }
390 span.white { color: white; }
391 span.yellow { color: yellow; }
393 span.aqua-background { background: aqua; }
394 span.black-background { background: black; }
395 span.blue-background { background: blue; }
396 span.fuchsia-background { background: fuchsia; }
397 span.gray-background { background: gray; }
398 span.green-background { background: green; }
399 span.lime-background { background: lime; }
400 span.maroon-background { background: maroon; }
401 span.navy-background { background: navy; }
402 span.olive-background { background: olive; }
403 span.purple-background { background: purple; }
404 span.red-background { background: red; }
405 span.silver-background { background: silver; }
406 span.teal-background { background: teal; }
407 span.white-background { background: white; }
408 span.yellow-background { background: yellow; }
410 span.big { font-size:
2em; }
411 span.small { font-size:
0.6em; }
413 span.underline { text-decoration: underline; }
414 span.overline { text-decoration: overline; }
415 span.line-through { text-decoration: line-through; }
417 div.unbreakable { page-break-inside: avoid; }
427 margin-bottom:
1.5em;
429 div.tableblock
> table {
430 border:
3px solid #
527bbd;
432 thead, p.table.header {
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
440 div.tableblock
> table[
frame=
"void"] {
443 div.tableblock
> table[
frame=
"hsides"] {
444 border-left-style: none;
445 border-right-style: none;
447 div.tableblock
> table[
frame=
"vsides"] {
448 border-top-style: none;
449 border-bottom-style: none;
460 margin-bottom:
1.5em;
462 thead, p.tableblock.header {
473 border-color: #
527bbd;
474 border-collapse: collapse;
476 th.tableblock, td.tableblock {
480 border-color: #
527bbd;
483 table.tableblock.frame-topbot {
484 border-left-style: hidden;
485 border-right-style: hidden;
487 table.tableblock.frame-sides {
488 border-top-style: hidden;
489 border-bottom-style: hidden;
491 table.tableblock.frame-none {
492 border-style: hidden;
495 th.tableblock.halign-left, td.tableblock.halign-left {
498 th.tableblock.halign-center, td.tableblock.halign-center {
501 th.tableblock.halign-right, td.tableblock.halign-right {
505 th.tableblock.valign-top, td.tableblock.valign-top {
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
509 vertical-align: middle;
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
512 vertical-align: bottom;
523 padding-bottom:
0.5em;
524 border-top:
2px solid silver;
525 border-bottom:
2px solid silver;
530 body.manpage div.sectionbody {
535 body.manpage div#toc { display: none; }
540 <script type=
"text/javascript">
542 var asciidoc = { // Namespace.
544 /////////////////////////////////////////////////////////////////////
545 // Table Of Contents generator
546 /////////////////////////////////////////////////////////////////////
548 /* Author: Mihai Bazon, September
2002
549 * http://students.infoiasi.ro/~mishoo
551 * Table Of Content generator
554 * Feel free to use this script under the terms of the GNU General Public
555 * License, as long as you do not remove or alter this notice.
558 /* modified by Troy D. Hanson, September
2006. License: GPL */
559 /* modified by Stuart Rackham,
2006,
2009. License: GPL */
562 toc: function (toclevels) {
564 function getText(el) {
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType ==
3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
569 else if (i.firstChild != null)
575 function TocEntry(el, text, toclevel) {
578 this.toclevel = toclevel;
581 function tocEntries(el, toclevels) {
582 var result = new Array;
583 var re = new RegExp('[hH]([
1-'+(toclevels+
1)+'])');
584 // Function that scans the DOM tree for header elements (the DOM2
585 // nodeIterator API would be a better technique but not supported by all
587 var iterate = function (el) {
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
589 if (i.nodeType ==
1 /* Node.ELEMENT_NODE */) {
590 var mo = re.exec(i.tagName);
591 if (mo && (i.getAttribute(
"class") || i.getAttribute(
"className")) !=
"float") {
592 result[result.length] = new TocEntry(i, getText(i), mo[
1]-
1);
602 var toc = document.getElementById(
"toc");
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
610 for (i =
0; i < toc.childNodes.length; i++) {
611 var entry = toc.childNodes[i];
612 if (entry.nodeName.toLowerCase() == 'div'
613 && entry.getAttribute(
"class")
614 && entry.getAttribute(
"class").match(/^toclevel/))
615 tocEntriesToRemove.push(entry);
617 for (i =
0; i < tocEntriesToRemove.length; i++) {
618 toc.removeChild(tocEntriesToRemove[i]);
621 // Rebuild TOC entries.
622 var entries = tocEntries(document.getElementById(
"content"), toclevels);
623 for (var i =
0; i < entries.length; ++i) {
624 var entry = entries[i];
625 if (entry.element.id ==
"")
626 entry.element.id =
"_toc_" + i;
627 var a = document.createElement(
"a");
628 a.href =
"#" + entry.element.id;
629 a.appendChild(document.createTextNode(entry.text));
630 var div = document.createElement(
"div");
632 div.className =
"toclevel" + entry.toclevel;
633 toc.appendChild(div);
635 if (entries.length ==
0)
636 toc.parentNode.removeChild(toc);
640 /////////////////////////////////////////////////////////////////////
641 // Footnotes generator
642 /////////////////////////////////////////////////////////////////////
644 /* Based on footnote generation code from:
645 * http://www.brandspankingnew.net/archive/
2005/
07/format_footnote.html
648 footnotes: function () {
649 // Delete existing footnote entries in case we're reloading the footnodes.
651 var noteholder = document.getElementById(
"footnotes");
655 var entriesToRemove = [];
656 for (i =
0; i < noteholder.childNodes.length; i++) {
657 var entry = noteholder.childNodes[i];
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute(
"class") ==
"footnote")
659 entriesToRemove.push(entry);
661 for (i =
0; i < entriesToRemove.length; i++) {
662 noteholder.removeChild(entriesToRemove[i]);
665 // Rebuild footnote entries.
666 var cont = document.getElementById(
"content");
667 var spans = cont.getElementsByTagName(
"span");
670 for (i=
0; i
<spans.length; i++) {
671 if (spans[i].className ==
"footnote") {
673 var note = spans[i].getAttribute(
"data-note");
675 // Use [\s\S] in place of . so multi-line matches work.
676 // Because JavaScript has no s (dotall) regex flag.
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[
1];
679 "[<a id='_footnoteref_" + n +
"' href='#_footnote_" + n +
680 "' title='View footnote' class='footnote'>" + n +
"</a>]";
681 spans[i].setAttribute(
"data-note", note);
683 noteholder.innerHTML +=
684 "<div class='footnote' id='_footnote_" + n +
"'>" +
685 "<a href='#_footnoteref_" + n +
"' title='Return to text'>" +
686 n +
"</a>. " + note +
"</div>";
687 var id =spans[i].getAttribute(
"id");
688 if (id != null) refs[
"#"+id] = n;
692 noteholder.parentNode.removeChild(noteholder);
694 // Process footnoterefs.
695 for (i=
0; i
<spans.length; i++) {
696 if (spans[i].className ==
"footnoteref") {
697 var href = spans[i].getElementsByTagName(
"a")[
0].getAttribute(
"href");
698 href = href.match(/#.*/)[
0]; // Because IE return full URL.
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n +
"</a>]";
708 install: function(toclevels) {
711 function reinstall() {
712 asciidoc.footnotes();
714 asciidoc.toc(toclevels);
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
723 timerId = setInterval(reinstall,
500);
724 if (document.addEventListener)
725 document.addEventListener(
"DOMContentLoaded", reinstallAndRemoveTimer, false);
727 window.onload = reinstallAndRemoveTimer;
735 <body class=
"manpage">
738 git-rebase(
1) Manual Page
741 <div class=
"sectionbody">
743 Reapply commits on top of another base tip
749 <h2 id=
"_synopsis">SYNOPSIS
</h2>
750 <div class=
"sectionbody">
751 <div class=
"verseblock">
752 <pre class=
"content"><em>git rebase
</em> [-i | --interactive] [
<options
>] [--exec
<cmd
>]
753 [--onto
<newbase
> | --keep-base] [
<upstream
> [
<branch
>]]
754 <em>git rebase
</em> [-i | --interactive] [
<options
>] [--exec
<cmd
>] [--onto
<newbase
>]
755 --root [
<branch
>]
756 <em>git rebase
</em> (--continue | --skip | --abort | --quit | --edit-todo | --show-current-patch)
</pre>
757 <div class=
"attribution">
762 <h2 id=
"_description">DESCRIPTION
</h2>
763 <div class=
"sectionbody">
764 <div class=
"paragraph"><p>If
<code><branch
></code> is specified,
<code>git rebase
</code> will perform an automatic
765 <code>git switch
<branch
></code> before doing anything else. Otherwise
766 it remains on the current branch.
</p></div>
767 <div class=
"paragraph"><p>If
<code><upstream
></code> is not specified, the upstream configured in
768 <code>branch.
<name
>.remote
</code> and
<code>branch.
<name
>.merge
</code> options will be used (see
769 <a href=
"git-config.html">git-config(
1)
</a> for details) and the
<code>--fork-point
</code> option is
770 assumed. If you are currently not on any branch or if the current
771 branch does not have a configured upstream, the rebase will abort.
</p></div>
772 <div class=
"paragraph"><p>All changes made by commits in the current branch but that are not
773 in
<code><upstream
></code> are saved to a temporary area. This is the same set
774 of commits that would be shown by
<code>git log
<upstream
>..HEAD
</code>; or by
775 <code>git log 'fork_point'..HEAD
</code>, if
<code>--fork-point
</code> is active (see the
776 description on
<code>--fork-point
</code> below); or by
<code>git log HEAD
</code>, if the
777 <code>--root
</code> option is specified.
</p></div>
778 <div class=
"paragraph"><p>The current branch is reset to
<code><upstream
></code> or
<code><newbase
></code> if the
779 <code>--onto
</code> option was supplied. This has the exact same effect as
780 <code>git reset --hard
<upstream
></code> (or
<code><newbase
></code>).
<code>ORIG_HEAD
</code> is set
781 to point at the tip of the branch before the reset.
</p></div>
782 <div class=
"admonitionblock">
785 <div class=
"title">Note
</div>
787 <td class=
"content"><code>ORIG_HEAD
</code> is not guaranteed to still point to the previous branch tip
788 at the end of the rebase if other commands that write that pseudo-ref
789 (e.g.
<code>git reset
</code>) are used during the rebase. The previous branch tip,
790 however, is accessible using the reflog of the current branch
791 (i.e.
<code>@{
1}
</code>, see
<a href=
"gitrevisions.html">gitrevisions(
7)
</a>).
</td>
794 <div class=
"paragraph"><p>The commits that were previously saved into the temporary area are
795 then reapplied to the current branch, one by one, in order. Note that
796 any commits in
<code>HEAD
</code> which introduce the same textual changes as a commit
797 in
<code>HEAD..
<upstream
></code> are omitted (i.e., a patch already accepted upstream
798 with a different commit message or timestamp will be skipped).
</p></div>
799 <div class=
"paragraph"><p>It is possible that a merge failure will prevent this process from being
800 completely automatic. You will have to resolve any such merge failure
801 and run
<code>git rebase --continue
</code>. Another option is to bypass the commit
802 that caused the merge failure with
<code>git rebase --skip
</code>. To check out the
803 original
<code><branch
></code> and remove the
<code>.git/rebase-apply
</code> working files, use
804 the command
<code>git rebase --abort
</code> instead.
</p></div>
805 <div class=
"paragraph"><p>Assume the following history exists and the current branch is
"topic":
</p></div>
806 <div class=
"listingblock">
807 <div class=
"content">
808 <pre><code> A---B---C topic
810 D---E---F---G master
</code></pre>
812 <div class=
"paragraph"><p>From this point, the result of either of the following commands:
</p></div>
813 <div class=
"literalblock">
814 <div class=
"content">
815 <pre><code>git rebase master
816 git rebase master topic
</code></pre>
818 <div class=
"paragraph"><p>would be:
</p></div>
819 <div class=
"listingblock">
820 <div class=
"content">
821 <pre><code> A'--B'--C' topic
823 D---E---F---G master
</code></pre>
825 <div class=
"paragraph"><p><strong>NOTE:
</strong> The latter form is just a short-hand of
<code>git checkout topic
</code>
826 followed by
<code>git rebase master
</code>. When rebase exits
<code>topic
</code> will
827 remain the checked-out branch.
</p></div>
828 <div class=
"paragraph"><p>If the upstream branch already contains a change you have made (e.g.,
829 because you mailed a patch which was applied upstream), then that commit
830 will be skipped and warnings will be issued (if the
<em>merge
</em> backend is
831 used). For example, running
<code>git rebase master
</code> on the following
832 history (in which
<code>A'
</code> and
<code>A
</code> introduce the same set of changes, but
833 have different committer information):
</p></div>
834 <div class=
"listingblock">
835 <div class=
"content">
836 <pre><code> A---B---C topic
838 D---E---A'---F master
</code></pre>
840 <div class=
"paragraph"><p>will result in:
</p></div>
841 <div class=
"listingblock">
842 <div class=
"content">
843 <pre><code> B'---C' topic
845 D---E---A'---F master
</code></pre>
847 <div class=
"paragraph"><p>Here is how you would transplant a topic branch based on one
848 branch to another, to pretend that you forked the topic branch
849 from the latter branch, using
<code>rebase --onto
</code>.
</p></div>
850 <div class=
"paragraph"><p>First let
’s assume your
<em>topic
</em> is based on branch
<em>next
</em>.
851 For example, a feature developed in
<em>topic
</em> depends on some
852 functionality which is found in
<em>next
</em>.
</p></div>
853 <div class=
"listingblock">
854 <div class=
"content">
855 <pre><code> o---o---o---o---o master
857 o---o---o---o---o next
859 o---o---o topic
</code></pre>
861 <div class=
"paragraph"><p>We want to make
<em>topic
</em> forked from branch
<em>master
</em>; for example,
862 because the functionality on which
<em>topic
</em> depends was merged into the
863 more stable
<em>master
</em> branch. We want our tree to look like this:
</p></div>
864 <div class=
"listingblock">
865 <div class=
"content">
866 <pre><code> o---o---o---o---o master
870 o---o---o---o---o next
</code></pre>
872 <div class=
"paragraph"><p>We can get this using the following command:
</p></div>
873 <div class=
"literalblock">
874 <div class=
"content">
875 <pre><code>git rebase --onto master next topic
</code></pre>
877 <div class=
"paragraph"><p>Another example of --onto option is to rebase part of a
878 branch. If we have the following situation:
</p></div>
879 <div class=
"listingblock">
880 <div class=
"content">
881 <pre><code> H---I---J topicB
885 A---B---C---D master
</code></pre>
887 <div class=
"paragraph"><p>then the command
</p></div>
888 <div class=
"literalblock">
889 <div class=
"content">
890 <pre><code>git rebase --onto master topicA topicB
</code></pre>
892 <div class=
"paragraph"><p>would result in:
</p></div>
893 <div class=
"listingblock">
894 <div class=
"content">
895 <pre><code> H'--I'--J' topicB
899 A---B---C---D master
</code></pre>
901 <div class=
"paragraph"><p>This is useful when topicB does not depend on topicA.
</p></div>
902 <div class=
"paragraph"><p>A range of commits could also be removed with rebase. If we have
903 the following situation:
</p></div>
904 <div class=
"listingblock">
905 <div class=
"content">
906 <pre><code> E---F---G---H---I---J topicA
</code></pre>
908 <div class=
"paragraph"><p>then the command
</p></div>
909 <div class=
"literalblock">
910 <div class=
"content">
911 <pre><code>git rebase --onto topicA~
5 topicA~
3 topicA
</code></pre>
913 <div class=
"paragraph"><p>would result in the removal of commits F and G:
</p></div>
914 <div class=
"listingblock">
915 <div class=
"content">
916 <pre><code> E---H'---I'---J' topicA
</code></pre>
918 <div class=
"paragraph"><p>This is useful if F and G were flawed in some way, or should not be
919 part of topicA. Note that the argument to
<code>--onto
</code> and the
<code><upstream
></code>
920 parameter can be any valid commit-ish.
</p></div>
921 <div class=
"paragraph"><p>In case of conflict,
<code>git rebase
</code> will stop at the first problematic commit
922 and leave conflict markers in the tree. You can use
<code>git diff
</code> to locate
923 the markers (
<<<<<<) and make edits to resolve the conflict. For each
924 file you edit, you need to tell Git that the conflict has been resolved,
925 typically this would be done with
</p></div>
926 <div class=
"literalblock">
927 <div class=
"content">
928 <pre><code>git add
<filename
></code></pre>
930 <div class=
"paragraph"><p>After resolving the conflict manually and updating the index with the
931 desired resolution, you can continue the rebasing process with
</p></div>
932 <div class=
"literalblock">
933 <div class=
"content">
934 <pre><code>git rebase --continue
</code></pre>
936 <div class=
"paragraph"><p>Alternatively, you can undo the
<em>git rebase
</em> with
</p></div>
937 <div class=
"literalblock">
938 <div class=
"content">
939 <pre><code>git rebase --abort
</code></pre>
944 <h2 id=
"_mode_options">MODE OPTIONS
</h2>
945 <div class=
"sectionbody">
946 <div class=
"paragraph"><p>The options in this section cannot be used with any other option,
947 including not with each other:
</p></div>
948 <div class=
"dlist"><dl>
954 Restart the rebasing process after having resolved a merge conflict.
962 Restart the rebasing process by skipping the current patch.
970 Abort the rebase operation and reset HEAD to the original
971 branch. If
<code><branch
></code> was provided when the rebase operation was
972 started, then
<code>HEAD
</code> will be reset to
<code><branch
></code>. Otherwise
<code>HEAD
</code>
973 will be reset to where it was when the rebase operation was
982 Abort the rebase operation but
<code>HEAD
</code> is not reset back to the
983 original branch. The index and working tree are also left
984 unchanged as a result. If a temporary stash entry was created
985 using
<code>--autostash
</code>, it will be saved to the stash list.
993 Edit the todo list during an interactive rebase.
1001 Show the current patch in an interactive rebase or when rebase
1002 is stopped because of conflicts. This is the equivalent of
1003 <code>git show REBASE_HEAD
</code>.
1010 <h2 id=
"_options">OPTIONS
</h2>
1011 <div class=
"sectionbody">
1012 <div class=
"dlist"><dl>
1013 <dt class=
"hdlist1">
1014 --onto
<newbase
>
1018 Starting point at which to create the new commits. If the
1019 <code>--onto
</code> option is not specified, the starting point is
1020 <code><upstream
></code>. May be any valid commit, and not just an
1021 existing branch name.
1023 <div class=
"paragraph"><p>As a special case, you may use
"A...B" as a shortcut for the
1024 merge base of A and B if there is exactly one merge base. You can
1025 leave out at most one of A and B, in which case it defaults to HEAD.
</p></div>
1027 <dt class=
"hdlist1">
1032 Set the starting point at which to create the new commits to the
1033 merge base of
<code><upstream
></code> and
<code><branch
></code>. Running
1034 <code>git rebase --keep-base
<upstream
> <branch
></code> is equivalent to
1036 <code>git rebase --reapply-cherry-picks --no-fork-point --onto
<upstream
>...
<branch
> <upstream
> <branch
></code>.
1038 <div class=
"paragraph"><p>This option is useful in the case where one is developing a feature on
1039 top of an upstream branch. While the feature is being worked on, the
1040 upstream branch may advance and it may not be the best idea to keep
1041 rebasing on top of the upstream but to keep the base commit as-is. As
1042 the base commit is unchanged this option implies
<code>--reapply-cherry-picks
</code>
1043 to avoid losing commits.
</p></div>
1044 <div class=
"paragraph"><p>Although both this option and
<code>--fork-point
</code> find the merge base between
1045 <code><upstream
></code> and
<code><branch
></code>, this option uses the merge base as the
<em>starting
1046 point
</em> on which new commits will be created, whereas
<code>--fork-point
</code> uses
1047 the merge base to determine the
<em>set of commits
</em> which will be rebased.
</p></div>
1048 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1050 <dt class=
"hdlist1">
1055 Upstream branch to compare against. May be any valid commit,
1056 not just an existing branch name. Defaults to the configured
1057 upstream for the current branch.
1060 <dt class=
"hdlist1">
1065 Working branch; defaults to
<code>HEAD
</code>.
1068 <dt class=
"hdlist1">
1073 Use applying strategies to rebase (calling
<code>git-am
</code>
1074 internally). This option may become a no-op in the future
1075 once the merge backend handles everything the apply one does.
1077 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1079 <dt class=
"hdlist1">
1080 --empty=(drop|keep|ask)
1084 How to handle commits that are not empty to start and are not
1085 clean cherry-picks of any upstream commit, but which become
1086 empty after rebasing (because they contain a subset of already
1087 upstream changes). With drop (the default), commits that
1088 become empty are dropped. With keep, such commits are kept.
1089 With ask (implied by
<code>--interactive
</code>), the rebase will halt when
1090 an empty commit is applied allowing you to choose whether to
1091 drop it, edit files more, or just commit the empty changes.
1092 Other options, like
<code>--exec
</code>, will use the default of drop unless
1093 <code>-i
</code>/
<code>--interactive
</code> is explicitly specified.
1095 <div class=
"paragraph"><p>Note that commits which start empty are kept (unless
<code>--no-keep-empty
</code>
1096 is specified), and commits which are clean cherry-picks (as determined
1097 by
<code>git log --cherry-mark ...
</code>) are detected and dropped as a
1098 preliminary step (unless
<code>--reapply-cherry-picks
</code> or
<code>--keep-base
</code> is
1100 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1102 <dt class=
"hdlist1">
1105 <dt class=
"hdlist1">
1110 Do not keep commits that start empty before the rebase
1111 (i.e. that do not change anything from its parent) in the
1112 result. The default is to keep commits which start empty,
1113 since creating such commits requires passing the
<code>--allow-empty
</code>
1114 override flag to
<code>git commit
</code>, signifying that a user is very
1115 intentionally creating such a commit and thus wants to keep
1118 <div class=
"paragraph"><p>Usage of this flag will probably be rare, since you can get rid of
1119 commits that start empty by just firing up an interactive rebase and
1120 removing the lines corresponding to the commits you don
’t want. This
1121 flag exists as a convenient shortcut, such as for cases where external
1122 tools generate many empty commits and you want them all removed.
</p></div>
1123 <div class=
"paragraph"><p>For commits which do not start empty but become empty after rebasing,
1124 see the
<code>--empty
</code> flag.
</p></div>
1125 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1127 <dt class=
"hdlist1">
1128 --reapply-cherry-picks
1130 <dt class=
"hdlist1">
1131 --no-reapply-cherry-picks
1135 Reapply all clean cherry-picks of any upstream commit instead
1136 of preemptively dropping them. (If these commits then become
1137 empty after rebasing, because they contain a subset of already
1138 upstream changes, the behavior towards them is controlled by
1139 the
<code>--empty
</code> flag.)
1141 <div class=
"paragraph"><p>In the absence of
<code>--keep-base
</code> (or if
<code>--no-reapply-cherry-picks
</code> is
1142 given), these commits will be automatically dropped. Because this
1143 necessitates reading all upstream commits, this can be expensive in
1144 repositories with a large number of upstream commits that need to be
1145 read. When using the
<em>merge
</em> backend, warnings will be issued for each
1146 dropped commit (unless
<code>--quiet
</code> is given). Advice will also be issued
1147 unless
<code>advice.skippedCherryPicks
</code> is set to false (see
1148 <a href=
"git-config.html">git-config(
1)
</a>).
</p></div>
1149 <div class=
"paragraph"><p><code>--reapply-cherry-picks
</code> allows rebase to forgo reading all upstream
1150 commits, potentially improving performance.
</p></div>
1151 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1153 <dt class=
"hdlist1">
1154 --allow-empty-message
1158 No-op. Rebasing commits with an empty message used to fail
1159 and this option would override that behavior, allowing commits
1160 with empty messages to be rebased. Now commits with an empty
1161 message do not cause rebasing to halt.
1163 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1165 <dt class=
"hdlist1">
1168 <dt class=
"hdlist1">
1173 Using merging strategies to rebase (default).
1175 <div class=
"paragraph"><p>Note that a rebase merge works by replaying each commit from the working
1176 branch on top of the
<code><upstream
></code> branch. Because of this, when a merge
1177 conflict happens, the side reported as
<em>ours
</em> is the so-far rebased
1178 series, starting with
<code><upstream
></code>, and
<em>theirs
</em> is the working branch.
1179 In other words, the sides are swapped.
</p></div>
1180 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1182 <dt class=
"hdlist1">
1185 <dt class=
"hdlist1">
1186 --strategy=
<strategy
>
1190 Use the given merge strategy, instead of the default
<code>ort
</code>.
1191 This implies
<code>--merge
</code>.
1193 <div class=
"paragraph"><p>Because
<code>git rebase
</code> replays each commit from the working branch
1194 on top of the
<code><upstream
></code> branch using the given strategy, using
1195 the
<code>ours
</code> strategy simply empties all patches from the
<code><branch
></code>,
1196 which makes little sense.
</p></div>
1197 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1199 <dt class=
"hdlist1">
1200 -X
<strategy-option
>
1202 <dt class=
"hdlist1">
1203 --strategy-option=
<strategy-option
>
1207 Pass the
<strategy-option
> through to the merge strategy.
1208 This implies
<code>--merge
</code> and, if no strategy has been
1209 specified,
<code>-s ort
</code>. Note the reversal of
<em>ours
</em> and
1210 <em>theirs
</em> as noted above for the
<code>-m
</code> option.
1212 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1214 <dt class=
"hdlist1">
1217 <dt class=
"hdlist1">
1218 --no-rerere-autoupdate
1222 After the rerere mechanism reuses a recorded resolution on
1223 the current conflict to update the files in the working
1224 tree, allow it to also update the index with the result of
1225 resolution.
<code>--no-rerere-autoupdate
</code> is a good way to
1226 double-check what
<code>rerere
</code> did and catch potential
1227 mismerges, before committing the result to the index with a
1228 separate
<code>git add
</code>.
1231 <dt class=
"hdlist1">
1234 <dt class=
"hdlist1">
1235 --gpg-sign[=
<keyid
>]
1237 <dt class=
"hdlist1">
1242 GPG-sign commits. The
<code>keyid
</code> argument is optional and
1243 defaults to the committer identity; if specified, it must be
1244 stuck to the option without a space.
<code>--no-gpg-sign
</code> is useful to
1245 countermand both
<code>commit.gpgSign
</code> configuration variable, and
1246 earlier
<code>--gpg-sign
</code>.
1249 <dt class=
"hdlist1">
1252 <dt class=
"hdlist1">
1257 Be quiet. Implies
<code>--no-stat
</code>.
1260 <dt class=
"hdlist1">
1263 <dt class=
"hdlist1">
1268 Be verbose. Implies
<code>--stat
</code>.
1271 <dt class=
"hdlist1">
1276 Show a diffstat of what changed upstream since the last rebase. The
1277 diffstat is also controlled by the configuration option rebase.stat.
1280 <dt class=
"hdlist1">
1283 <dt class=
"hdlist1">
1288 Do not show a diffstat as part of the rebase process.
1291 <dt class=
"hdlist1">
1296 This option bypasses the pre-rebase hook. See also
<a href=
"githooks.html">githooks(
5)
</a>.
1299 <dt class=
"hdlist1">
1304 Allows the pre-rebase hook to run, which is the default. This option can
1305 be used to override
<code>--no-verify
</code>. See also
<a href=
"githooks.html">githooks(
5)
</a>.
1308 <dt class=
"hdlist1">
1313 Ensure at least
<code><n
></code> lines of surrounding context match before
1314 and after each change. When fewer lines of surrounding
1315 context exist they all must match. By default no context is
1316 ever ignored. Implies
<code>--apply
</code>.
1318 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1320 <dt class=
"hdlist1">
1323 <dt class=
"hdlist1">
1326 <dt class=
"hdlist1">
1331 Individually replay all rebased commits instead of fast-forwarding
1332 over the unchanged ones. This ensures that the entire history of
1333 the rebased branch is composed of new commits.
1335 <div class=
"paragraph"><p>You may find this helpful after reverting a topic branch merge, as this option
1336 recreates the topic branch with fresh commits so it can be remerged
1337 successfully without needing to
"revert the reversion" (see the
1338 <a href=
"howto/revert-a-faulty-merge.html">revert-a-faulty-merge How-To
</a> for
1341 <dt class=
"hdlist1">
1344 <dt class=
"hdlist1">
1349 Use reflog to find a better common ancestor between
<code><upstream
></code>
1350 and
<code><branch
></code> when calculating which commits have been
1351 introduced by
<code><branch
></code>.
1353 <div class=
"paragraph"><p>When
<code>--fork-point
</code> is active,
<em>fork_point
</em> will be used instead of
1354 <code><upstream
></code> to calculate the set of commits to rebase, where
1355 <em>fork_point
</em> is the result of
<code>git merge-base --fork-point
<upstream
>
1356 <branch
></code> command (see
<a href=
"git-merge-base.html">git-merge-base(
1)
</a>). If
<em>fork_point
</em>
1357 ends up being empty, the
<code><upstream
></code> will be used as a fallback.
</p></div>
1358 <div class=
"paragraph"><p>If
<code><upstream
></code> or
<code>--keep-base
</code> is given on the command line, then
1359 the default is
<code>--no-fork-point
</code>, otherwise the default is
1360 <code>--fork-point
</code>. See also
<code>rebase.forkpoint
</code> in
<a href=
"git-config.html">git-config(
1)
</a>.
</p></div>
1361 <div class=
"paragraph"><p>If your branch was based on
<code><upstream
></code> but
<code><upstream
></code> was rewound and
1362 your branch contains commits which were dropped, this option can be used
1363 with
<code>--keep-base
</code> in order to drop those commits from your branch.
</p></div>
1364 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1366 <dt class=
"hdlist1">
1371 Ignore whitespace differences when trying to reconcile
1372 differences. Currently, each backend implements an approximation of
1375 <div class=
"dlist"><dl>
1376 <dt class=
"hdlist1">
1381 When applying a patch, ignore changes in whitespace in context
1382 lines. Unfortunately, this means that if the
"old" lines being
1383 replaced by the patch differ only in whitespace from the existing
1384 file, you will get a merge conflict instead of a successful patch
1388 <dt class=
"hdlist1">
1393 Treat lines with only whitespace changes as unchanged when merging.
1394 Unfortunately, this means that any patch hunks that were intended
1395 to modify whitespace and nothing else will be dropped, even if the
1396 other side had no changes that conflicted.
1401 <dt class=
"hdlist1">
1402 --whitespace=
<option
>
1406 This flag is passed to the
<code>git apply
</code> program
1407 (see
<a href=
"git-apply.html">git-apply(
1)
</a>) that applies the patch.
1408 Implies
<code>--apply
</code>.
1410 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1412 <dt class=
"hdlist1">
1413 --committer-date-is-author-date
1417 Instead of using the current time as the committer date, use
1418 the author date of the commit being rebased as the committer
1419 date. This option implies
<code>--force-rebase
</code>.
1422 <dt class=
"hdlist1">
1425 <dt class=
"hdlist1">
1430 Instead of using the author date of the original commit, use
1431 the current time as the author date of the rebased commit. This
1432 option implies
<code>--force-rebase
</code>.
1434 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1436 <dt class=
"hdlist1">
1441 Add a
<code>Signed-off-by
</code> trailer to all the rebased commits. Note
1442 that if
<code>--interactive
</code> is given then only commits marked to be
1443 picked, edited or reworded will have the trailer added.
1445 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1447 <dt class=
"hdlist1">
1450 <dt class=
"hdlist1">
1455 Make a list of the commits which are about to be rebased. Let the
1456 user edit that list before rebasing. This mode can also be used to
1457 split commits (see SPLITTING COMMITS below).
1459 <div class=
"paragraph"><p>The commit list format can be changed by setting the configuration option
1460 rebase.instructionFormat. A customized instruction format will automatically
1461 have the commit hash prepended to the format.
</p></div>
1462 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1464 <dt class=
"hdlist1">
1467 <dt class=
"hdlist1">
1468 --rebase-merges[=(rebase-cousins|no-rebase-cousins)]
1470 <dt class=
"hdlist1">
1475 By default, a rebase will simply drop merge commits from the todo
1476 list, and put the rebased commits into a single, linear branch.
1477 With
<code>--rebase-merges
</code>, the rebase will instead try to preserve
1478 the branching structure within the commits that are to be rebased,
1479 by recreating the merge commits. Any resolved merge conflicts or
1480 manual amendments in these merge commits will have to be
1481 resolved/re-applied manually.
<code>--no-rebase-merges
</code> can be used to
1482 countermand both the
<code>rebase.rebaseMerges
</code> config option and a previous
1483 <code>--rebase-merges
</code>.
1485 <div class=
"paragraph"><p>When rebasing merges, there are two modes:
<code>rebase-cousins
</code> and
1486 <code>no-rebase-cousins
</code>. If the mode is not specified, it defaults to
1487 <code>no-rebase-cousins
</code>. In
<code>no-rebase-cousins
</code> mode, commits which do not have
1488 <code><upstream
></code> as direct ancestor will keep their original branch point, i.e.
1489 commits that would be excluded by
<a href=
"git-log.html">git-log(
1)
</a>'s
<code>--ancestry-path
</code>
1490 option will keep their original ancestry by default. In
<code>rebase-cousins
</code> mode,
1491 such commits are instead rebased onto
<code><upstream
></code> (or
<code><onto
></code>, if
1492 specified).
</p></div>
1493 <div class=
"paragraph"><p>It is currently only possible to recreate the merge commits using the
1494 <code>ort
</code> merge strategy; different merge strategies can be used only via
1495 explicit
<code>exec git merge -s
<strategy
> [...]
</code> commands.
</p></div>
1496 <div class=
"paragraph"><p>See also REBASING MERGES and INCOMPATIBLE OPTIONS below.
</p></div>
1498 <dt class=
"hdlist1">
1501 <dt class=
"hdlist1">
1506 Append
"exec <cmd>" after each line creating a commit in the
1507 final history.
<code><cmd
></code> will be interpreted as one or more shell
1508 commands. Any command that fails will interrupt the rebase,
1511 <div class=
"paragraph"><p>You may execute several commands by either using one instance of
<code>--exec
</code>
1512 with several commands:
</p></div>
1513 <div class=
"literalblock">
1514 <div class=
"content">
1515 <pre><code>git rebase -i --exec
"cmd1 && cmd2 && ..."</code></pre>
1517 <div class=
"paragraph"><p>or by giving more than one
<code>--exec
</code>:
</p></div>
1518 <div class=
"literalblock">
1519 <div class=
"content">
1520 <pre><code>git rebase -i --exec
"cmd1" --exec
"cmd2" --exec ...
</code></pre>
1522 <div class=
"paragraph"><p>If
<code>--autosquash
</code> is used,
<code>exec
</code> lines will not be appended for
1523 the intermediate commits, and will only appear at the end of each
1524 squash/fixup series.
</p></div>
1525 <div class=
"paragraph"><p>This uses the
<code>--interactive
</code> machinery internally, but it can be run
1526 without an explicit
<code>--interactive
</code>.
</p></div>
1527 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1529 <dt class=
"hdlist1">
1534 Rebase all commits reachable from
<code><branch
></code>, instead of
1535 limiting them with an
<code><upstream
></code>. This allows you to rebase
1536 the root commit(s) on a branch.
1538 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1540 <dt class=
"hdlist1">
1543 <dt class=
"hdlist1">
1548 Automatically squash commits with specially formatted messages into
1549 previous commits being rebased. If a commit message starts with
1550 "squash! ",
"fixup! " or
"amend! ", the remainder of the subject line
1551 is taken as a commit specifier, which matches a previous commit if it
1552 matches the subject line or the hash of that commit. If no commit
1553 matches fully, matches of the specifier with the start of commit
1554 subjects are considered.
1556 <div class=
"paragraph"><p>In the rebase todo list, the actions of squash, fixup and amend commits are
1557 changed from
<code>pick
</code> to
<code>squash
</code>,
<code>fixup
</code> or
<code>fixup -C
</code>, respectively, and they
1558 are moved right after the commit they modify. The
<code>--interactive
</code> option can
1559 be used to review and edit the todo list before proceeding.
</p></div>
1560 <div class=
"paragraph"><p>The recommended way to create commits with squash markers is by using the
1561 <code>--squash
</code>,
<code>--fixup
</code>,
<code>--fixup=amend:
</code> or
<code>--fixup=reword:
</code> options of
1562 <a href=
"git-commit.html">git-commit(
1)
</a>, which take the target commit as an argument and
1563 automatically fill in the subject line of the new commit from that.
</p></div>
1564 <div class=
"paragraph"><p>Settting configuration variable
<code>rebase.autoSquash
</code> to true enables
1565 auto-squashing by default for interactive rebase. The
<code>--no-autosquash
</code>
1566 option can be used to override that setting.
</p></div>
1567 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1569 <dt class=
"hdlist1">
1572 <dt class=
"hdlist1">
1577 Automatically create a temporary stash entry before the operation
1578 begins, and apply it after the operation ends. This means
1579 that you can run rebase on a dirty worktree. However, use
1580 with care: the final stash application after a successful
1581 rebase might result in non-trivial conflicts.
1584 <dt class=
"hdlist1">
1585 --reschedule-failed-exec
1587 <dt class=
"hdlist1">
1588 --no-reschedule-failed-exec
1592 Automatically reschedule
<code>exec
</code> commands that failed. This only makes
1593 sense in interactive mode (or when an
<code>--exec
</code> option was provided).
1595 <div class=
"paragraph"><p>This option applies once a rebase is started. It is preserved for the whole
1596 rebase based on, in order, the command line option provided to the initial
<code>git
1597 rebase
</code>, the
<code>rebase.rescheduleFailedExec
</code> configuration (see
1598 <a href=
"git-config.html">git-config(
1)
</a> or
"CONFIGURATION" below), or it defaults to false.
</p></div>
1599 <div class=
"paragraph"><p>Recording this option for the whole rebase is a convenience feature. Otherwise
1600 an explicit
<code>--no-reschedule-failed-exec
</code> at the start would be overridden by
1601 the presence of a
<code>rebase.rescheduleFailedExec=true
</code> configuration when
<code>git
1602 rebase --continue
</code> is invoked. Currently, you cannot pass
1603 <code>--[no-]reschedule-failed-exec
</code> to
<code>git rebase --continue
</code>.
</p></div>
1605 <dt class=
"hdlist1">
1608 <dt class=
"hdlist1">
1613 Automatically force-update any branches that point to commits that
1614 are being rebased. Any branches that are checked out in a worktree
1615 are not updated in this way.
1617 <div class=
"paragraph"><p>If the configuration variable
<code>rebase.updateRefs
</code> is set, then this option
1618 can be used to override and disable this setting.
</p></div>
1619 <div class=
"paragraph"><p>See also INCOMPATIBLE OPTIONS below.
</p></div>
1625 <h2 id=
"_incompatible_options">INCOMPATIBLE OPTIONS
</h2>
1626 <div class=
"sectionbody">
1627 <div class=
"paragraph"><p>The following options:
</p></div>
1628 <div class=
"ulist"><ul>
1645 <div class=
"paragraph"><p>are incompatible with the following options:
</p></div>
1646 <div class=
"ulist"><ul>
1694 --[no-]reapply-cherry-picks when used without --keep-base
1704 --root when used without --onto
1708 <div class=
"paragraph"><p>In addition, the following pairs of options are incompatible:
</p></div>
1709 <div class=
"ulist"><ul>
1712 --keep-base and --onto
1717 --keep-base and --root
1722 --fork-point and --root
1729 <h2 id=
"_behavioral_differences">BEHAVIORAL DIFFERENCES
</h2>
1730 <div class=
"sectionbody">
1731 <div class=
"paragraph"><p><code>git rebase
</code> has two primary backends:
<em>apply
</em> and
<em>merge
</em>. (The
<em>apply
</em>
1732 backend used to be known as the
<em>am
</em> backend, but the name led to
1733 confusion as it looks like a verb instead of a noun. Also, the
<em>merge
</em>
1734 backend used to be known as the interactive backend, but it is now
1735 used for non-interactive cases as well. Both were renamed based on
1736 lower-level functionality that underpinned each.) There are some
1737 subtle differences in how these two backends behave:
</p></div>
1739 <h3 id=
"_empty_commits">Empty commits
</h3>
1740 <div class=
"paragraph"><p>The
<em>apply
</em> backend unfortunately drops intentionally empty commits, i.e.
1741 commits that started empty, though these are rare in practice. It
1742 also drops commits that become empty and has no option for controlling
1743 this behavior.
</p></div>
1744 <div class=
"paragraph"><p>The
<em>merge
</em> backend keeps intentionally empty commits by default (though
1745 with
<code>-i
</code> they are marked as empty in the todo list editor, or they can
1746 be dropped automatically with
<code>--no-keep-empty
</code>).
</p></div>
1747 <div class=
"paragraph"><p>Similar to the apply backend, by default the merge backend drops
1748 commits that become empty unless
<code>-i
</code>/
<code>--interactive
</code> is specified (in
1749 which case it stops and asks the user what to do). The merge backend
1750 also has an
<code>--empty=(drop|keep|ask)
</code> option for changing the behavior
1751 of handling commits that become empty.
</p></div>
1754 <h3 id=
"_directory_rename_detection">Directory rename detection
</h3>
1755 <div class=
"paragraph"><p>Due to the lack of accurate tree information (arising from
1756 constructing fake ancestors with the limited information available in
1757 patches), directory rename detection is disabled in the
<em>apply
</em> backend.
1758 Disabled directory rename detection means that if one side of history
1759 renames a directory and the other adds new files to the old directory,
1760 then the new files will be left behind in the old directory without
1761 any warning at the time of rebasing that you may want to move these
1762 files into the new directory.
</p></div>
1763 <div class=
"paragraph"><p>Directory rename detection works with the
<em>merge
</em> backend to provide you
1764 warnings in such cases.
</p></div>
1767 <h3 id=
"_context">Context
</h3>
1768 <div class=
"paragraph"><p>The
<em>apply
</em> backend works by creating a sequence of patches (by calling
1769 <code>format-patch
</code> internally), and then applying the patches in sequence
1770 (calling
<code>am
</code> internally). Patches are composed of multiple hunks,
1771 each with line numbers, a context region, and the actual changes. The
1772 line numbers have to be taken with some fuzz, since the other side
1773 will likely have inserted or deleted lines earlier in the file. The
1774 context region is meant to help find how to adjust the line numbers in
1775 order to apply the changes to the right lines. However, if multiple
1776 areas of the code have the same surrounding lines of context, the
1777 wrong one can be picked. There are real-world cases where this has
1778 caused commits to be reapplied incorrectly with no conflicts reported.
1779 Setting
<code>diff.context
</code> to a larger value may prevent such types of
1780 problems, but increases the chance of spurious conflicts (since it
1781 will require more lines of matching context to apply).
</p></div>
1782 <div class=
"paragraph"><p>The
<em>merge
</em> backend works with a full copy of each relevant file,
1783 insulating it from these types of problems.
</p></div>
1786 <h3 id=
"_labelling_of_conflicts_markers">Labelling of conflicts markers
</h3>
1787 <div class=
"paragraph"><p>When there are content conflicts, the merge machinery tries to
1788 annotate each side
’s conflict markers with the commits where the
1789 content came from. Since the
<em>apply
</em> backend drops the original
1790 information about the rebased commits and their parents (and instead
1791 generates new fake commits based off limited information in the
1792 generated patches), those commits cannot be identified; instead it has
1793 to fall back to a commit summary. Also, when
<code>merge.conflictStyle
</code> is
1794 set to
<code>diff3
</code> or
<code>zdiff3
</code>, the
<em>apply
</em> backend will use
"constructed merge
1795 base" to label the content from the merge base, and thus provide no
1796 information about the merge base commit whatsoever.
</p></div>
1797 <div class=
"paragraph"><p>The
<em>merge
</em> backend works with the full commits on both sides of history
1798 and thus has no such limitations.
</p></div>
1801 <h3 id=
"_hooks">Hooks
</h3>
1802 <div class=
"paragraph"><p>The
<em>apply
</em> backend has not traditionally called the post-commit hook,
1803 while the
<em>merge
</em> backend has. Both have called the post-checkout hook,
1804 though the
<em>merge
</em> backend has squelched its output. Further, both
1805 backends only call the post-checkout hook with the starting point
1806 commit of the rebase, not the intermediate commits nor the final
1807 commit. In each case, the calling of these hooks was by accident of
1808 implementation rather than by design (both backends were originally
1809 implemented as shell scripts and happened to invoke other commands
1810 like
<code>git checkout
</code> or
<code>git commit
</code> that would call the hooks). Both
1811 backends should have the same behavior, though it is not entirely
1812 clear which, if any, is correct. We will likely make rebase stop
1813 calling either of these hooks in the future.
</p></div>
1816 <h3 id=
"_interruptability">Interruptability
</h3>
1817 <div class=
"paragraph"><p>The
<em>apply
</em> backend has safety problems with an ill-timed interrupt; if
1818 the user presses Ctrl-C at the wrong time to try to abort the rebase,
1819 the rebase can enter a state where it cannot be aborted with a
1820 subsequent
<code>git rebase --abort
</code>. The
<em>merge
</em> backend does not appear to
1821 suffer from the same shortcoming. (See
1822 <a href=
"https://lore.kernel.org/git/20200207132152.GC2868@szeder.dev/">https://lore.kernel.org/git/
20200207132152.GC2868@szeder.dev/
</a> for
1826 <h3 id=
"_commit_rewording">Commit Rewording
</h3>
1827 <div class=
"paragraph"><p>When a conflict occurs while rebasing, rebase stops and asks the user
1828 to resolve. Since the user may need to make notable changes while
1829 resolving conflicts, after conflicts are resolved and the user has run
1830 <code>git rebase --continue
</code>, the rebase should open an editor and ask the
1831 user to update the commit message. The
<em>merge
</em> backend does this, while
1832 the
<em>apply
</em> backend blindly applies the original commit message.
</p></div>
1835 <h3 id=
"_miscellaneous_differences">Miscellaneous differences
</h3>
1836 <div class=
"paragraph"><p>There are a few more behavioral differences that most folks would
1837 probably consider inconsequential but which are mentioned for
1838 completeness:
</p></div>
1839 <div class=
"ulist"><ul>
1842 Reflog: The two backends will use different wording when describing
1843 the changes made in the reflog, though both will make use of the
1849 Progress, informational, and error messages: The two backends
1850 provide slightly different progress and informational messages.
1851 Also, the apply backend writes error messages (such as
"Your files
1852 would be overwritten…") to stdout, while the merge backend writes
1858 State directories: The two backends keep their state in different
1859 directories under
<code>.git/
</code>
1867 <h2 id=
"_merge_strategies">MERGE STRATEGIES
</h2>
1868 <div class=
"sectionbody">
1869 <div class=
"paragraph"><p>The merge mechanism (
<code>git merge
</code> and
<code>git pull
</code> commands) allows the
1870 backend
<em>merge strategies
</em> to be chosen with
<code>-s
</code> option. Some strategies
1871 can also take their own options, which can be passed by giving
<code>-X
<option
></code>
1872 arguments to
<code>git merge
</code> and/or
<code>git pull
</code>.
</p></div>
1873 <div class=
"dlist"><dl>
1874 <dt class=
"hdlist1">
1879 This is the default merge strategy when pulling or merging one
1880 branch. This strategy can only resolve two heads using a
1881 3-way merge algorithm. When there is more than one common
1882 ancestor that can be used for
3-way merge, it creates a merged
1883 tree of the common ancestors and uses that as the reference
1884 tree for the
3-way merge. This has been reported to result in
1885 fewer merge conflicts without causing mismerges by tests done
1886 on actual merge commits taken from Linux
2.6 kernel
1887 development history. Additionally this strategy can detect
1888 and handle merges involving renames. It does not make use of
1889 detected copies. The name for this algorithm is an acronym
1890 (
"Ostensibly Recursive’s Twin") and came from the fact that it
1891 was written as a replacement for the previous default
1892 algorithm,
<code>recursive
</code>.
1894 <div class=
"paragraph"><p>The
<em>ort
</em> strategy can take the following options:
</p></div>
1895 <div class=
"dlist"><dl>
1896 <dt class=
"hdlist1">
1901 This option forces conflicting hunks to be auto-resolved cleanly by
1902 favoring
<em>our
</em> version. Changes from the other tree that do not
1903 conflict with our side are reflected in the merge result.
1904 For a binary file, the entire contents are taken from our side.
1906 <div class=
"paragraph"><p>This should not be confused with the
<em>ours
</em> merge strategy, which does not
1907 even look at what the other tree contains at all. It discards everything
1908 the other tree did, declaring
<em>our
</em> history contains all that happened in it.
</p></div>
1910 <dt class=
"hdlist1">
1915 This is the opposite of
<em>ours
</em>; note that, unlike
<em>ours
</em>, there is
1916 no
<em>theirs
</em> merge strategy to confuse this merge option with.
1919 <dt class=
"hdlist1">
1922 <dt class=
"hdlist1">
1925 <dt class=
"hdlist1">
1928 <dt class=
"hdlist1">
1933 Treats lines with the indicated type of whitespace change as
1934 unchanged for the sake of a three-way merge. Whitespace
1935 changes mixed with other changes to a line are not ignored.
1936 See also
<a href=
"git-diff.html">git-diff(
1)
</a> <code>-b
</code>,
<code>-w
</code>,
1937 <code>--ignore-space-at-eol
</code>, and
<code>--ignore-cr-at-eol
</code>.
1939 <div class=
"ulist"><ul>
1942 If
<em>their
</em> version only introduces whitespace changes to a line,
1943 <em>our
</em> version is used;
1948 If
<em>our
</em> version introduces whitespace changes but
<em>their
</em>
1949 version includes a substantial change,
<em>their
</em> version is used;
1954 Otherwise, the merge proceeds in the usual way.
1959 <dt class=
"hdlist1">
1964 This runs a virtual check-out and check-in of all three stages
1965 of a file when resolving a three-way merge. This option is
1966 meant to be used when merging branches with different clean
1967 filters or end-of-line normalization rules. See
"Merging
1968 branches with differing checkin/checkout attributes" in
1969 <a href=
"gitattributes.html">gitattributes(
5)
</a> for details.
1972 <dt class=
"hdlist1">
1977 Disables the
<code>renormalize
</code> option. This overrides the
1978 <code>merge.renormalize
</code> configuration variable.
1981 <dt class=
"hdlist1">
1982 find-renames[=
<n
>]
1986 Turn on rename detection, optionally setting the similarity
1987 threshold. This is the default. This overrides the
1988 <em>merge.renames
</em> configuration variable.
1989 See also
<a href=
"git-diff.html">git-diff(
1)
</a> <code>--find-renames
</code>.
1992 <dt class=
"hdlist1">
1993 rename-threshold=
<n
>
1997 Deprecated synonym for
<code>find-renames=
<n
></code>.
2000 <dt class=
"hdlist1">
2001 subtree[=
<path
>]
2005 This option is a more advanced form of
<em>subtree
</em> strategy, where
2006 the strategy makes a guess on how two trees must be shifted to
2007 match with each other when merging. Instead, the specified path
2008 is prefixed (or stripped from the beginning) to make the shape of
2014 <dt class=
"hdlist1">
2019 This can only resolve two heads using a
3-way merge
2020 algorithm. When there is more than one common
2021 ancestor that can be used for
3-way merge, it creates a
2022 merged tree of the common ancestors and uses that as
2023 the reference tree for the
3-way merge. This has been
2024 reported to result in fewer merge conflicts without
2025 causing mismerges by tests done on actual merge commits
2026 taken from Linux
2.6 kernel development history.
2027 Additionally this can detect and handle merges involving
2028 renames. It does not make use of detected copies. This was
2029 the default strategy for resolving two heads from Git v0.99
.9k
2032 <div class=
"paragraph"><p>The
<em>recursive
</em> strategy takes the same options as
<em>ort
</em>. However,
2033 there are three additional options that
<em>ort
</em> ignores (not documented
2034 above) that are potentially useful with the
<em>recursive
</em> strategy:
</p></div>
2035 <div class=
"dlist"><dl>
2036 <dt class=
"hdlist1">
2041 Deprecated synonym for
<code>diff-algorithm=patience
</code>.
2044 <dt class=
"hdlist1">
2045 diff-algorithm=[patience|minimal|histogram|myers]
2049 Use a different diff algorithm while merging, which can help
2050 avoid mismerges that occur due to unimportant matching lines
2051 (such as braces from distinct functions). See also
2052 <a href=
"git-diff.html">git-diff(
1)
</a> <code>--diff-algorithm
</code>. Note that
<code>ort
</code>
2053 specifically uses
<code>diff-algorithm=histogram
</code>, while
<code>recursive
</code>
2054 defaults to the
<code>diff.algorithm
</code> config setting.
2057 <dt class=
"hdlist1">
2062 Turn off rename detection. This overrides the
<code>merge.renames
</code>
2063 configuration variable.
2064 See also
<a href=
"git-diff.html">git-diff(
1)
</a> <code>--no-renames
</code>.
2069 <dt class=
"hdlist1">
2074 This can only resolve two heads (i.e. the current branch
2075 and another branch you pulled from) using a
3-way merge
2076 algorithm. It tries to carefully detect criss-cross
2077 merge ambiguities. It does not handle renames.
2080 <dt class=
"hdlist1">
2085 This resolves cases with more than two heads, but refuses to do
2086 a complex merge that needs manual resolution. It is
2087 primarily meant to be used for bundling topic branch
2088 heads together. This is the default merge strategy when
2089 pulling or merging more than one branch.
2092 <dt class=
"hdlist1">
2097 This resolves any number of heads, but the resulting tree of the
2098 merge is always that of the current branch head, effectively
2099 ignoring all changes from all other branches. It is meant to
2100 be used to supersede old development history of side
2101 branches. Note that this is different from the -Xours option to
2102 the
<em>recursive
</em> merge strategy.
2105 <dt class=
"hdlist1">
2110 This is a modified
<code>ort
</code> strategy. When merging trees A and
2111 B, if B corresponds to a subtree of A, B is first adjusted to
2112 match the tree structure of A, instead of reading the trees at
2113 the same level. This adjustment is also done to the common
2118 <div class=
"paragraph"><p>With the strategies that use
3-way merge (including the default,
<em>ort
</em>),
2119 if a change is made on both branches, but later reverted on one of the
2120 branches, that change will be present in the merged result; some people find
2121 this behavior confusing. It occurs because only the heads and the merge base
2122 are considered when performing a merge, not the individual commits. The merge
2123 algorithm therefore considers the reverted change as no change at all, and
2124 substitutes the changed version instead.
</p></div>
2128 <h2 id=
"_notes">NOTES
</h2>
2129 <div class=
"sectionbody">
2130 <div class=
"paragraph"><p>You should understand the implications of using
<code>git rebase
</code> on a
2131 repository that you share. See also RECOVERING FROM UPSTREAM REBASE
2133 <div class=
"paragraph"><p>When the rebase is run, it will first execute a
<code>pre-rebase
</code> hook if one
2134 exists. You can use this hook to do sanity checks and reject the rebase
2135 if it isn
’t appropriate. Please see the template
<code>pre-rebase
</code> hook script
2136 for an example.
</p></div>
2137 <div class=
"paragraph"><p>Upon completion,
<code><branch
></code> will be the current branch.
</p></div>
2141 <h2 id=
"_interactive_mode">INTERACTIVE MODE
</h2>
2142 <div class=
"sectionbody">
2143 <div class=
"paragraph"><p>Rebasing interactively means that you have a chance to edit the commits
2144 which are rebased. You can reorder the commits, and you can
2145 remove them (weeding out bad or otherwise unwanted patches).
</p></div>
2146 <div class=
"paragraph"><p>The interactive mode is meant for this type of workflow:
</p></div>
2147 <div class=
"olist arabic"><ol class=
"arabic">
2150 have a wonderful idea
2160 prepare a series for submission
2169 <div class=
"paragraph"><p>where point
2. consists of several instances of
</p></div>
2170 <div class=
"paragraph"><p>a) regular use
</p></div>
2171 <div class=
"olist arabic"><ol class=
"arabic">
2174 finish something worthy of a commit
2183 <div class=
"paragraph"><p>b) independent fixup
</p></div>
2184 <div class=
"olist arabic"><ol class=
"arabic">
2187 realize that something does not work
2201 <div class=
"paragraph"><p>Sometimes the thing fixed in b
.2. cannot be amended to the not-quite
2202 perfect commit it fixes, because that commit is buried deeply in a
2203 patch series. That is exactly what interactive rebase is for: use it
2204 after plenty of
"a"s and
"b"s, by rearranging and editing
2205 commits, and squashing multiple commits into one.
</p></div>
2206 <div class=
"paragraph"><p>Start it with the last commit you want to retain as-is:
</p></div>
2207 <div class=
"literalblock">
2208 <div class=
"content">
2209 <pre><code>git rebase -i
<after-this-commit
></code></pre>
2211 <div class=
"paragraph"><p>An editor will be fired up with all the commits in your current branch
2212 (ignoring merge commits), which come after the given commit. You can
2213 reorder the commits in this list to your heart
’s content, and you can
2214 remove them. The list looks more or less like this:
</p></div>
2215 <div class=
"listingblock">
2216 <div class=
"content">
2217 <pre><code>pick deadbee The oneline of this commit
2218 pick fa1afe1 The oneline of the next commit
2221 <div class=
"paragraph"><p>The oneline descriptions are purely for your pleasure;
<em>git rebase
</em> will
2222 not look at them but at the commit names (
"deadbee" and
"fa1afe1" in this
2223 example), so do not delete or edit the names.
</p></div>
2224 <div class=
"paragraph"><p>By replacing the command
"pick" with the command
"edit", you can tell
2225 <code>git rebase
</code> to stop after applying that commit, so that you can edit
2226 the files and/or the commit message, amend the commit, and continue
2228 <div class=
"paragraph"><p>To interrupt the rebase (just like an
"edit" command would do, but without
2229 cherry-picking any commit first), use the
"break" command.
</p></div>
2230 <div class=
"paragraph"><p>If you just want to edit the commit message for a commit, replace the
2231 command
"pick" with the command
"reword".
</p></div>
2232 <div class=
"paragraph"><p>To drop a commit, replace the command
"pick" with
"drop", or just
2233 delete the matching line.
</p></div>
2234 <div class=
"paragraph"><p>If you want to fold two or more commits into one, replace the command
2235 "pick" for the second and subsequent commits with
"squash" or
"fixup".
2236 If the commits had different authors, the folded commit will be
2237 attributed to the author of the first commit. The suggested commit
2238 message for the folded commit is the concatenation of the first
2239 commit
’s message with those identified by
"squash" commands, omitting the
2240 messages of commits identified by
"fixup" commands, unless
"fixup -c"
2241 is used. In that case the suggested commit message is only the message
2242 of the
"fixup -c" commit, and an editor is opened allowing you to edit
2243 the message. The contents (patch) of the
"fixup -c" commit are still
2244 incorporated into the folded commit. If there is more than one
"fixup -c"
2245 commit, the message from the final one is used. You can also use
2246 "fixup -C" to get the same behavior as
"fixup -c" except without opening
2247 an editor.
</p></div>
2248 <div class=
"paragraph"><p><code>git rebase
</code> will stop when
"pick" has been replaced with
"edit" or
2249 when a command fails due to merge errors. When you are done editing
2250 and/or resolving conflicts you can continue with
<code>git rebase --continue
</code>.
</p></div>
2251 <div class=
"paragraph"><p>For example, if you want to reorder the last
5 commits, such that what
2252 was
<code>HEAD~
4</code> becomes the new
<code>HEAD
</code>. To achieve that, you would call
2253 <code>git rebase
</code> like this:
</p></div>
2254 <div class=
"listingblock">
2255 <div class=
"content">
2256 <pre><code>$ git rebase -i HEAD~
5</code></pre>
2258 <div class=
"paragraph"><p>And move the first patch to the end of the list.
</p></div>
2259 <div class=
"paragraph"><p>You might want to recreate merge commits, e.g. if you have a history
2260 like this:
</p></div>
2261 <div class=
"listingblock">
2262 <div class=
"content">
2267 ---o---O---P---Q
</code></pre>
2269 <div class=
"paragraph"><p>Suppose you want to rebase the side branch starting at
"A" to
"Q". Make
2270 sure that the current
<code>HEAD
</code> is
"B", and call
</p></div>
2271 <div class=
"listingblock">
2272 <div class=
"content">
2273 <pre><code>$ git rebase -i -r --onto Q O
</code></pre>
2275 <div class=
"paragraph"><p>Reordering and editing commits usually creates untested intermediate
2276 steps. You may want to check that your history editing did not break
2277 anything by running a test, or at least recompiling at intermediate
2278 points in history by using the
"exec" command (shortcut
"x"). You may
2279 do so by creating a todo list like this one:
</p></div>
2280 <div class=
"listingblock">
2281 <div class=
"content">
2282 <pre><code>pick deadbee Implement feature XXX
2283 fixup f1a5c00 Fix to feature XXX
2285 pick c0ffeee The oneline of the next commit
2286 edit deadbab The oneline of the commit after
2287 exec cd subdir; make test
2290 <div class=
"paragraph"><p>The interactive rebase will stop when a command fails (i.e. exits with
2291 non-
0 status) to give you an opportunity to fix the problem. You can
2292 continue with
<code>git rebase --continue
</code>.
</p></div>
2293 <div class=
"paragraph"><p>The
"exec" command launches the command in a shell (the one specified
2294 in
<code>$SHELL
</code>, or the default shell if
<code>$SHELL
</code> is not set), so you can
2295 use shell features (like
"cd",
">",
";" …). The command is run from
2296 the root of the working tree.
</p></div>
2297 <div class=
"listingblock">
2298 <div class=
"content">
2299 <pre><code>$ git rebase -i --exec
"make test"</code></pre>
2301 <div class=
"paragraph"><p>This command lets you check that intermediate commits are compilable.
2302 The todo list becomes like that:
</p></div>
2303 <div class=
"listingblock">
2304 <div class=
"content">
2305 <pre><code>pick
5928aea one
2312 exec make test
</code></pre>
2317 <h2 id=
"_splitting_commits">SPLITTING COMMITS
</h2>
2318 <div class=
"sectionbody">
2319 <div class=
"paragraph"><p>In interactive mode, you can mark commits with the action
"edit". However,
2320 this does not necessarily mean that
<code>git rebase
</code> expects the result of this
2321 edit to be exactly one commit. Indeed, you can undo the commit, or you can
2322 add other commits. This can be used to split a commit into two:
</p></div>
2323 <div class=
"ulist"><ul>
2326 Start an interactive rebase with
<code>git rebase -i
<commit
>^
</code>, where
2327 <code><commit
></code> is the commit you want to split. In fact, any commit range
2328 will do, as long as it contains that commit.
2333 Mark the commit you want to split with the action
"edit".
2338 When it comes to editing that commit, execute
<code>git reset HEAD^
</code>. The
2339 effect is that the
<code>HEAD
</code> is rewound by one, and the index follows suit.
2340 However, the working tree stays the same.
2345 Now add the changes to the index that you want to have in the first
2346 commit. You can use
<code>git add
</code> (possibly interactively) or
2347 <code>git gui
</code> (or both) to do that.
2352 Commit the now-current index with whatever commit message is appropriate
2358 Repeat the last two steps until your working tree is clean.
2363 Continue the rebase with
<code>git rebase --continue
</code>.
2367 <div class=
"paragraph"><p>If you are not absolutely sure that the intermediate revisions are
2368 consistent (they compile, pass the testsuite, etc.) you should use
2369 <code>git stash
</code> to stash away the not-yet-committed changes
2370 after each commit, test, and amend the commit if fixes are necessary.
</p></div>
2374 <h2 id=
"_recovering_from_upstream_rebase">RECOVERING FROM UPSTREAM REBASE
</h2>
2375 <div class=
"sectionbody">
2376 <div class=
"paragraph"><p>Rebasing (or any other form of rewriting) a branch that others have
2377 based work on is a bad idea: anyone downstream of it is forced to
2378 manually fix their history. This section explains how to do the fix
2379 from the downstream
’s point of view. The real fix, however, would be
2380 to avoid rebasing the upstream in the first place.
</p></div>
2381 <div class=
"paragraph"><p>To illustrate, suppose you are in a situation where someone develops a
2382 <em>subsystem
</em> branch, and you are working on a
<em>topic
</em> that is dependent
2383 on this
<em>subsystem
</em>. You might end up with a history like the
2384 following:
</p></div>
2385 <div class=
"listingblock">
2386 <div class=
"content">
2387 <pre><code> o---o---o---o---o---o---o---o master
2389 o---o---o---o---o subsystem
2391 *---*---* topic
</code></pre>
2393 <div class=
"paragraph"><p>If
<em>subsystem
</em> is rebased against
<em>master
</em>, the following happens:
</p></div>
2394 <div class=
"listingblock">
2395 <div class=
"content">
2396 <pre><code> o---o---o---o---o---o---o---o master
2398 o---o---o---o---o o'--o'--o'--o'--o' subsystem
2400 *---*---* topic
</code></pre>
2402 <div class=
"paragraph"><p>If you now continue development as usual, and eventually merge
<em>topic
</em>
2403 to
<em>subsystem
</em>, the commits from
<em>subsystem
</em> will remain duplicated forever:
</p></div>
2404 <div class=
"listingblock">
2405 <div class=
"content">
2406 <pre><code> o---o---o---o---o---o---o---o master
2408 o---o---o---o---o o'--o'--o'--o'--o'--M subsystem
2410 *---*---*-..........-*--* topic
</code></pre>
2412 <div class=
"paragraph"><p>Such duplicates are generally frowned upon because they clutter up
2413 history, making it harder to follow. To clean things up, you need to
2414 transplant the commits on
<em>topic
</em> to the new
<em>subsystem
</em> tip, i.e.,
2415 rebase
<em>topic
</em>. This becomes a ripple effect: anyone downstream from
2416 <em>topic
</em> is forced to rebase too, and so on!
</p></div>
2417 <div class=
"paragraph"><p>There are two kinds of fixes, discussed in the following subsections:
</p></div>
2418 <div class=
"dlist"><dl>
2419 <dt class=
"hdlist1">
2420 Easy case: The changes are literally the same.
2424 This happens if the
<em>subsystem
</em> rebase was a simple rebase and
2428 <dt class=
"hdlist1">
2429 Hard case: The changes are not the same.
2433 This happens if the
<em>subsystem
</em> rebase had conflicts, or used
2434 <code>--interactive
</code> to omit, edit, squash, or fixup commits; or
2435 if the upstream used one of
<code>commit --amend
</code>,
<code>reset
</code>, or
2436 a full history rewriting command like
2437 <a href=
"https://github.com/newren/git-filter-repo"><code>filter-repo
</code></a>.
2442 <h3 id=
"_the_easy_case">The easy case
</h3>
2443 <div class=
"paragraph"><p>Only works if the changes (patch IDs based on the diff contents) on
2444 <em>subsystem
</em> are literally the same before and after the rebase
2445 <em>subsystem
</em> did.
</p></div>
2446 <div class=
"paragraph"><p>In that case, the fix is easy because
<em>git rebase
</em> knows to skip
2447 changes that are already present in the new upstream (unless
2448 <code>--reapply-cherry-picks
</code> is given). So if you say
2449 (assuming you
’re on
<em>topic
</em>)
</p></div>
2450 <div class=
"listingblock">
2451 <div class=
"content">
2452 <pre><code> $ git rebase subsystem
</code></pre>
2454 <div class=
"paragraph"><p>you will end up with the fixed history
</p></div>
2455 <div class=
"listingblock">
2456 <div class=
"content">
2457 <pre><code> o---o---o---o---o---o---o---o master
2459 o'--o'--o'--o'--o' subsystem
2461 *---*---* topic
</code></pre>
2465 <h3 id=
"_the_hard_case">The hard case
</h3>
2466 <div class=
"paragraph"><p>Things get more complicated if the
<em>subsystem
</em> changes do not exactly
2467 correspond to the ones before the rebase.
</p></div>
2468 <div class=
"admonitionblock">
2471 <div class=
"title">Note
</div>
2473 <td class=
"content">While an
"easy case recovery" sometimes appears to be successful
2474 even in the hard case, it may have unintended consequences. For
2475 example, a commit that was removed via
<code>git rebase
2476 --interactive
</code> will be
<strong>resurrected
</strong>!
</td>
2479 <div class=
"paragraph"><p>The idea is to manually tell
<code>git rebase
</code> "where the old <em>subsystem</em>
2480 ended and your <em>topic</em> began", that is, what the old merge base
2481 between them was. You will have to find a way to name the last commit
2482 of the old
<em>subsystem
</em>, for example:
</p></div>
2483 <div class=
"ulist"><ul>
2486 With the
<em>subsystem
</em> reflog: after
<code>git fetch
</code>, the old tip of
2487 <em>subsystem
</em> is at
<code>subsystem@{
1}
</code>. Subsequent fetches will
2488 increase the number. (See
<a href=
"git-reflog.html">git-reflog(
1)
</a>.)
2493 Relative to the tip of
<em>topic
</em>: knowing that your
<em>topic
</em> has three
2494 commits, the old tip of
<em>subsystem
</em> must be
<code>topic~
3</code>.
2498 <div class=
"paragraph"><p>You can then transplant the old
<code>subsystem..topic
</code> to the new tip by
2499 saying (for the reflog case, and assuming you are on
<em>topic
</em> already):
</p></div>
2500 <div class=
"listingblock">
2501 <div class=
"content">
2502 <pre><code> $ git rebase --onto subsystem subsystem@{
1}
</code></pre>
2504 <div class=
"paragraph"><p>The ripple effect of a
"hard case" recovery is especially bad:
2505 <em>everyone
</em> downstream from
<em>topic
</em> will now have to perform a
"hard
2506 case" recovery too!
</p></div>
2511 <h2 id=
"_rebasing_merges">REBASING MERGES
</h2>
2512 <div class=
"sectionbody">
2513 <div class=
"paragraph"><p>The interactive rebase command was originally designed to handle
2514 individual patch series. As such, it makes sense to exclude merge
2515 commits from the todo list, as the developer may have merged the
2516 then-current
<code>master
</code> while working on the branch, only to rebase
2517 all the commits onto
<code>master
</code> eventually (skipping the merge
2519 <div class=
"paragraph"><p>However, there are legitimate reasons why a developer may want to
2520 recreate merge commits: to keep the branch structure (or
"commit
2521 topology") when working on multiple, inter-related branches.
</p></div>
2522 <div class=
"paragraph"><p>In the following example, the developer works on a topic branch that
2523 refactors the way buttons are defined, and on another topic branch
2524 that uses that refactoring to implement a
"Report a bug" button. The
2525 output of
<code>git log --graph --format=%s -
5</code> may look like this:
</p></div>
2526 <div class=
"listingblock">
2527 <div class=
"content">
2528 <pre><code>* Merge branch 'report-a-bug'
2530 | * Add the feedback button
2531 * | Merge branch 'refactor-button'
2534 | * Use the Button class for all buttons
2535 | * Extract a generic Button class from the DownloadButton one
</code></pre>
2537 <div class=
"paragraph"><p>The developer might want to rebase those commits to a newer
<code>master
</code>
2538 while keeping the branch topology, for example when the first topic
2539 branch is expected to be integrated into
<code>master
</code> much earlier than the
2540 second one, say, to resolve merge conflicts with changes to the
2541 DownloadButton class that made it into
<code>master
</code>.
</p></div>
2542 <div class=
"paragraph"><p>This rebase can be performed using the
<code>--rebase-merges
</code> option.
2543 It will generate a todo list looking like this:
</p></div>
2544 <div class=
"listingblock">
2545 <div class=
"content">
2546 <pre><code>label onto
2548 # Branch: refactor-button
2550 pick
123456 Extract a generic Button class from the DownloadButton one
2551 pick
654321 Use the Button class for all buttons
2552 label refactor-button
2554 # Branch: report-a-bug
2555 reset refactor-button # Use the Button class for all buttons
2556 pick abcdef Add the feedback button
2560 merge -C a1b2c3 refactor-button # Merge 'refactor-button'
2561 merge -C
6f5e4d report-a-bug # Merge 'report-a-bug'
</code></pre>
2563 <div class=
"paragraph"><p>In contrast to a regular interactive rebase, there are
<code>label
</code>,
<code>reset
</code>
2564 and
<code>merge
</code> commands in addition to
<code>pick
</code> ones.
</p></div>
2565 <div class=
"paragraph"><p>The
<code>label
</code> command associates a label with the current HEAD when that
2566 command is executed. These labels are created as worktree-local refs
2567 (
<code>refs/rewritten/
<label
></code>) that will be deleted when the rebase
2568 finishes. That way, rebase operations in multiple worktrees linked to
2569 the same repository do not interfere with one another. If the
<code>label
</code>
2570 command fails, it is rescheduled immediately, with a helpful message how
2571 to proceed.
</p></div>
2572 <div class=
"paragraph"><p>The
<code>reset
</code> command resets the HEAD, index and worktree to the specified
2573 revision. It is similar to an
<code>exec git reset --hard
<label
></code>, but
2574 refuses to overwrite untracked files. If the
<code>reset
</code> command fails, it is
2575 rescheduled immediately, with a helpful message how to edit the todo list
2576 (this typically happens when a
<code>reset
</code> command was inserted into the todo
2577 list manually and contains a typo).
</p></div>
2578 <div class=
"paragraph"><p>The
<code>merge
</code> command will merge the specified revision(s) into whatever
2579 is HEAD at that time. With
<code>-C
<original-commit
></code>, the commit message of
2580 the specified merge commit will be used. When the
<code>-C
</code> is changed to
2581 a lower-case
<code>-c
</code>, the message will be opened in an editor after a
2582 successful merge so that the user can edit the message.
</p></div>
2583 <div class=
"paragraph"><p>If a
<code>merge
</code> command fails for any reason other than merge conflicts (i.e.
2584 when the merge operation did not even start), it is rescheduled immediately.
</p></div>
2585 <div class=
"paragraph"><p>By default, the
<code>merge
</code> command will use the
<code>ort
</code> merge strategy for
2586 regular merges, and
<code>octopus
</code> for octopus merges. One can specify a
2587 default strategy for all merges using the
<code>--strategy
</code> argument when
2588 invoking rebase, or can override specific merges in the interactive
2589 list of commands by using an
<code>exec
</code> command to call
<code>git merge
</code>
2590 explicitly with a
<code>--strategy
</code> argument. Note that when calling
<code>git
2591 merge
</code> explicitly like this, you can make use of the fact that the
2592 labels are worktree-local refs (the ref
<code>refs/rewritten/onto
</code> would
2593 correspond to the label
<code>onto
</code>, for example) in order to refer to the
2594 branches you want to merge.
</p></div>
2595 <div class=
"paragraph"><p>Note: the first command (
<code>label onto
</code>) labels the revision onto which
2596 the commits are rebased; The name
<code>onto
</code> is just a convention, as a nod
2597 to the
<code>--onto
</code> option.
</p></div>
2598 <div class=
"paragraph"><p>It is also possible to introduce completely new merge commits from scratch
2599 by adding a command of the form
<code>merge
<merge-head
></code>. This form will
2600 generate a tentative commit message and always open an editor to let the
2601 user edit it. This can be useful e.g. when a topic branch turns out to
2602 address more than a single concern and wants to be split into two or
2603 even more topic branches. Consider this todo list:
</p></div>
2604 <div class=
"listingblock">
2605 <div class=
"content">
2606 <pre><code>pick
192837 Switch from GNU Makefiles to CMake
2607 pick
5a6c7e Document the switch to CMake
2608 pick
918273 Fix detection of OpenSSL in CMake
2609 pick afbecd http: add support for TLS v1.3
2610 pick fdbaec Fix detection of cURL in CMake on Windows
</code></pre>
2612 <div class=
"paragraph"><p>The one commit in this list that is not related to CMake may very well
2613 have been motivated by working on fixing all those bugs introduced by
2614 switching to CMake, but it addresses a different concern. To split this
2615 branch into two topic branches, the todo list could be edited like this:
</p></div>
2616 <div class=
"listingblock">
2617 <div class=
"content">
2618 <pre><code>label onto
2620 pick afbecd http: add support for TLS v1.3
2624 pick
192837 Switch from GNU Makefiles to CMake
2625 pick
918273 Fix detection of OpenSSL in CMake
2626 pick fdbaec Fix detection of cURL in CMake on Windows
2627 pick
5a6c7e Document the switch to CMake
2632 merge cmake
</code></pre>
2637 <h2 id=
"_configuration">CONFIGURATION
</h2>
2638 <div class=
"sectionbody">
2639 <div class=
"paragraph"><p>Everything below this line in this section is selectively included
2640 from the
<a href=
"git-config.html">git-config(
1)
</a> documentation. The content is the same
2641 as what
’s found there:
</p></div>
2642 <div class=
"dlist"><dl>
2643 <dt class=
"hdlist1">
2648 Default backend to use for rebasing. Possible choices are
2649 <em>apply
</em> or
<em>merge
</em>. In the future, if the merge backend gains
2650 all remaining capabilities of the apply backend, this setting
2654 <dt class=
"hdlist1">
2659 Whether to show a diffstat of what changed upstream since the last
2660 rebase. False by default.
2663 <dt class=
"hdlist1">
2668 If set to true, enable the
<code>--autosquash
</code> option of
2669 <a href=
"git-rebase.html">git-rebase(
1)
</a> by default for interactive mode.
2670 This can be overridden with the
<code>--no-autosquash
</code> option.
2673 <dt class=
"hdlist1">
2678 When set to true, automatically create a temporary stash entry
2679 before the operation begins, and apply it after the operation
2680 ends. This means that you can run rebase on a dirty worktree.
2681 However, use with care: the final stash application after a
2682 successful rebase might result in non-trivial conflicts.
2683 This option can be overridden by the
<code>--no-autostash
</code> and
2684 <code>--autostash
</code> options of
<a href=
"git-rebase.html">git-rebase(
1)
</a>.
2688 <dt class=
"hdlist1">
2693 If set to true enable
<code>--update-refs
</code> option by default.
2696 <dt class=
"hdlist1">
2697 rebase.missingCommitsCheck
2701 If set to
"warn", git rebase -i will print a warning if some
2702 commits are removed (e.g. a line was deleted), however the
2703 rebase will still proceed. If set to
"error", it will print
2704 the previous warning and stop the rebase,
<em>git rebase
2705 --edit-todo
</em> can then be used to correct the error. If set to
2706 "ignore", no checking is done.
2707 To drop a commit without warning or error, use the
<code>drop
</code>
2708 command in the todo list.
2709 Defaults to
"ignore".
2712 <dt class=
"hdlist1">
2713 rebase.instructionFormat
2717 A format string, as specified in
<a href=
"git-log.html">git-log(
1)
</a>, to be used for the
2718 todo list during an interactive rebase. The format will
2719 automatically have the commit hash prepended to the format.
2722 <dt class=
"hdlist1">
2723 rebase.abbreviateCommands
2727 If set to true,
<code>git rebase
</code> will use abbreviated command names in the
2728 todo list resulting in something like this:
2730 <div class=
"listingblock">
2731 <div class=
"content">
2732 <pre><code> p deadbee The oneline of the commit
2733 p fa1afe1 The oneline of the next commit
2736 <div class=
"paragraph"><p>instead of:
</p></div>
2737 <div class=
"listingblock">
2738 <div class=
"content">
2739 <pre><code> pick deadbee The oneline of the commit
2740 pick fa1afe1 The oneline of the next commit
2743 <div class=
"paragraph"><p>Defaults to false.
</p></div>
2745 <dt class=
"hdlist1">
2746 rebase.rescheduleFailedExec
2750 Automatically reschedule
<code>exec
</code> commands that failed. This only makes
2751 sense in interactive mode (or when an
<code>--exec
</code> option was provided).
2752 This is the same as specifying the
<code>--reschedule-failed-exec
</code> option.
2755 <dt class=
"hdlist1">
2760 If set to false set
<code>--no-fork-point
</code> option by default.
2763 <dt class=
"hdlist1">
2768 Whether and how to set the
<code>--rebase-merges
</code> option by default. Can
2769 be
<code>rebase-cousins
</code>,
<code>no-rebase-cousins
</code>, or a boolean. Setting to
2770 true or to
<code>no-rebase-cousins
</code> is equivalent to
2771 <code>--rebase-merges=no-rebase-cousins
</code>, setting to
<code>rebase-cousins
</code> is
2772 equivalent to
<code>--rebase-merges=rebase-cousins
</code>, and setting to false is
2773 equivalent to
<code>--no-rebase-merges
</code>. Passing
<code>--rebase-merges
</code> on the
2774 command line, with or without an argument, overrides any
2775 <code>rebase.rebaseMerges
</code> configuration.
2778 <dt class=
"hdlist1">
2779 rebase.maxLabelLength
2783 When generating label names from commit subjects, truncate the names to
2784 this length. By default, the names are truncated to a little less than
2785 <code>NAME_MAX
</code> (to allow e.g.
<code>.lock
</code> files to be written for the
2786 corresponding loose refs).
2789 <dt class=
"hdlist1">
2794 Text editor used by
<code>git rebase -i
</code> for editing the rebase instruction file.
2795 The value is meant to be interpreted by the shell when it is used.
2796 It can be overridden by the
<code>GIT_SEQUENCE_EDITOR
</code> environment variable.
2797 When not configured, the default commit message editor is used instead.
2804 <h2 id=
"_git">GIT
</h2>
2805 <div class=
"sectionbody">
2806 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
2810 <div id=
"footnotes"><hr /></div>
2812 <div id=
"footer-text">
2814 2024-
01-
16 12:
41:
37 PST