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">
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">
10 p
, li
, dt
, dd
, div
, pre
, h1
, h2
, h3
, h4
, h5
, h6
{
12 border: 1px solid red;
17 margin: 1em 5% 1em 5%;
22 text-decoration: underline
;
42 h1
, h2
, h3
, h4
, h5
, h6
{
44 font-family: sans-serif
;
51 border-bottom: 2px solid silver
;
69 border: 1px solid silver
;
88 font-family: sans-serif
;
94 span#revnumber
, span#revdate
, span#revremark
{
95 font-family: sans-serif
;
99 font-family: sans-serif
;
101 border-top: 2px solid silver
;
107 padding-bottom: 0.5em;
111 padding-bottom: 0.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
{
122 margin-bottom: 1.5em;
124 div
.admonitionblock
{
126 margin-bottom: 2.0em;
131 div
.content
{ /* Block element content. */
135 /* Block element titles. */
136 div
.title
, caption
.title
{
138 font-family: sans-serif
;
142 margin-bottom: 0.5em;
148 td div
.title:first-child
{
151 div
.content div
.title:first-child
{
154 div
.content
+ div
.title
{
158 div
.sidebarblock
> div
.content
{
160 border: 1px solid silver
;
164 div
.listingblock
> div
.content
{
165 border: 1px solid silver
;
170 div
.quoteblock
, div
.verseblock
{
174 border-left: 5px solid
#dddddd;
178 div
.quoteblock
> div
.attribution
{
183 div
.verseblock
> div
.content
{
186 div
.verseblock
> div
.attribution
{
190 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
191 div
.verseblock
+ div
.attribution
{
195 div
.admonitionblock
.icon
{
199 text-decoration: underline
;
201 padding-right: 0.5em;
203 div
.admonitionblock td
.content
{
205 border-left: 3px solid
#dddddd;
208 div
.exampleblock
> div
.content
{
209 border-left: 3px solid
#dddddd;
213 div
.imageblock div
.content
{ padding-left: 0; }
214 span
.image img
{ border-style: none
; }
215 a
.image:visited
{ color: white
; }
219 margin-bottom: 0.8em;
232 list-style-position: outside
;
235 list-style-type: decimal
;
238 list-style-type: lower-alpha
;
241 list-style-type: upper-alpha
;
244 list-style-type: lower-roman
;
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
{
254 margin-bottom: 0.1em;
257 div
.tableblock
> table
{
258 border: 3px solid
#527bbd;
260 thead
, p
.table
.header
{
261 font-family: sans-serif
;
273 /* Because the table frame attribute is overriden by CSS in most browsers. */
274 div
.tableblock
> table
[frame
="void"] {
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
;
289 margin-bottom: 0.8em;
292 padding-bottom: 15px;
294 dt
.hdlist1
.strong
, td
.hdlist1
.strong
{
300 padding-right: 0.8em;
306 div
.hdlist
.compact tr
{
315 .footnote, .footnoteref {
319 span
.footnote
, span
.footnoteref
{
320 vertical-align: super
;
324 margin: 20px 0 20px 0;
328 #footnotes div
.footnote
{
334 border-top: 1px solid silver
;
344 div#footer-badges
{ display: none
; }
348 margin-bottom: 2.5em;
353 font-family: sans-serif
;
357 margin-bottom: 0.1em;
360 div
.toclevel1
, div
.toclevel2
, div
.toclevel3
, div
.toclevel4
{
376 /* Overrides for manpage documents */
379 padding-bottom: 0.5em;
380 border-top: 2px solid silver
;
381 border-bottom: 2px solid silver
;
391 div#toc
{ display: none
; }
394 /* Workarounds for IE6's broken and incomplete CSS2. */
396 div
.sidebar-content
{
398 border: 1px solid silver
;
401 div
.sidebar-title
, div
.image-title
{
403 font-family: sans-serif
;
406 margin-bottom: 0.5em;
409 div
.listingblock div
.content
{
410 border: 1px solid silver
;
415 div
.quoteblock-attribution
{
420 div
.verseblock-content
{
423 div
.verseblock-attribution
{
428 div
.exampleblock-content
{
429 border-left: 3px solid
#dddddd;
433 /* IE6 sets dynamically generated links as visited. */
434 div#toc
a:visited
{ color: blue
; }
436 <script type=
"text/javascript">
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
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 */
459 toc: function (toclevels
) {
461 function getText(el
) {
463 for (var i
= el
.firstChild
; i
!= null; i
= i
.nextSibling
) {
464 if (i
.nodeType
== 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
466 else if (i
.firstChild
!= null)
472 function TocEntry(el
, text
, toclevel
) {
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
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);
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");
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");
532 for (i
=0; i
<spans
.length
; i
++) {
533 if (spans
[i
].className
== "footnote") {
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>";
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
;
550 noteholder
.parentNode
.removeChild(noteholder
);
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.
559 "[<a href='#_footnote_" + n
+
560 "' title='View footnote' class='footnote'>" + n
+ "</a>]";
573 git-rebase(
1) Manual Page
576 <div class=
"sectionbody">
578 Forward-port local commits to the updated upstream head
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
<newbase
>]
587 [
<upstream
>] [
<branch
>]
588 <em>git rebase
</em> [-i | --interactive] [options] --onto
<newbase
>
589 --root [
<branch
>]
590 <em>git rebase
</em> --continue | --skip | --abort
</div>
591 <div class=
"verseblock-attribution">
594 <h2 id=
"_description">DESCRIPTION
</h2>
595 <div class=
"sectionbody">
596 <div class=
"paragraph"><p>If
<branch
> is specified,
<em>git rebase
</em> will perform an automatic
597 <tt>git checkout
<branch
></tt> before doing anything else. Otherwise
598 it remains on the current branch.
</p></div>
599 <div class=
"paragraph"><p>If
<upstream
> is not specified, the upstream configured in
600 branch.
<name
>.remote and branch.
<name
>.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
<upstream
> are saved to a temporary area. This is the same set
606 of commits that would be shown by
<tt>git log
<upstream
>..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
<upstream
>, or
<newbase
> if the
609 --onto option was supplied. This has the exact same effect as
610 <tt>git reset --hard
<upstream
></tt> (or
<newbase
>). 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..
<upstream
> 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
<branch
> 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>
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>
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>
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
‘git rebase master` on the
649 following history (in which A
’ 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>
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>
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
’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>
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
687 o---o---o---o---o next
</tt></pre>
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>
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
702 A---B---C---D master
</tt></pre>
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>
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
716 A---B---C---D master
</tt></pre>
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>
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>
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>
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
<upstream
>
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 (
<<<<<<) 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
<filename
></tt></pre>
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>
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>
759 <h2 id=
"_configuration">CONFIGURATION
</h2>
760 <div class=
"sectionbody">
761 <div class=
"dlist"><dl>
767 Whether to show a diffstat of what changed upstream since the last
768 rebase. False by default.
776 If set to true enable
<em>--autosquash
</em> option by default.
781 <h2 id=
"_options">OPTIONS
</h2>
782 <div class=
"sectionbody">
783 <div class=
"dlist"><dl>
789 Starting point at which to create the new commits. If the
790 --onto option is not specified, the starting point is
791 <upstream
>. May be any valid commit, and not just an
792 existing branch name.
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>
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.
813 Working branch; defaults to HEAD.
821 Restart the rebasing process after having resolved a merge conflict.
829 Abort the rebase operation and reset HEAD to the original
830 branch. If
<branch
> was provided when the rebase operation was
831 started, then HEAD will be reset to
<branch
>. Otherwise HEAD
832 will be reset to where it was when the rebase operation was
841 Restart the rebasing process by skipping the current patch.
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
856 <div class=
"paragraph"><p>Note that a rebase merge works by replaying each commit from the working
857 branch on top of the
<upstream
> 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
<upstream
>, and
<em>theirs
</em> is the working branch. In
860 other words, the sides are swapped.
</p></div>
866 --strategy=
<strategy
>
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.
874 <div class=
"paragraph"><p>Because
<em>git rebase
</em> replays each commit from the working branch
875 on top of the
<upstream
> branch using the given strategy, using
876 the
<em>ours
</em> strategy simply discards all patches from the
<branch
>,
877 which makes little sense.
</p></div>
880 -X
<strategy-option
>
883 --strategy-option=
<strategy-option
>
887 Pass the
<strategy-option
> 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.
901 Be quiet. Implies --no-stat.
912 Be verbose. Implies --stat.
920 Show a diffstat of what changed upstream since the last rebase. The
921 diffstat is also controlled by the configuration option rebase.stat.
932 Do not show a diffstat as part of the rebase process.
940 This option bypasses the pre-rebase hook. See also
<a href=
"githooks.html">githooks(
5)
</a>.
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>.
957 Ensure at least
<n
> 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
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
975 Incompatible with the --interactive option.
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>
987 --whitespace=
<option
>
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.
997 --committer-date-is-author-date
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.
1009 <dt class=
"hdlist1">
1012 <dt class=
"hdlist1">
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).
1022 <dt class=
"hdlist1">
1025 <dt class=
"hdlist1">
1030 Instead of ignoring merges, try to recreate them.
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>
1036 <dt class=
"hdlist1">
1041 Rebase all commits reachable from
<branch
>, instead of
1042 limiting them with an
<upstream
>. 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
<newbase
> (instead of
1045 <upstream
>). When used together with --preserve-merges,
<em>all
</em>
1046 root commits will be rewritten to have
<newbase
> as parent
1050 <dt class=
"hdlist1">
1053 <dt class=
"hdlist1">
1058 When the commit log message begins with
"squash! …" (or
1059 "fixup! …"), and there is a commit whose title begins with
1060 the same
…, 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>).
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>
1070 <dt class=
"hdlist1">
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.
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>
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
<option
></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">
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
1106 <dt class=
"hdlist1">
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.
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">
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.
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>
1138 <dt class=
"hdlist1">
1143 This is opposite of
<em>ours
</em>.
1146 <dt class=
"hdlist1">
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>.
1158 <dt class=
"hdlist1">
1161 <dt class=
"hdlist1">
1164 <dt class=
"hdlist1">
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>.
1175 <div class=
"ulist"><ul>
1178 If
<em>their
</em> version only introduces whitespace changes to a line,
1179 <em>our
</em> version is used;
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;
1190 Otherwise, the merge proceeds in the usual way.
1195 <dt class=
"hdlist1">
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.
1208 <dt class=
"hdlist1">
1213 Disables the
<tt>renormalize
</tt> option. This overrides the
1214 <tt>merge.renormalize
</tt> configuration variable.
1217 <dt class=
"hdlist1">
1218 rename-threshold=
<n
>
1222 Controls the similarity threshold used for rename detection.
1223 See also
<a href=
"git-diff.html">git-diff(
1)
</a> <tt>-M
</tt>.
1226 <dt class=
"hdlist1">
1227 subtree[=
<path
>]
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
1240 <dt class=
"hdlist1">
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.
1252 <dt class=
"hdlist1">
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.
1265 <dt class=
"hdlist1">
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
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
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
’t appropriate. Please see the template
1287 pre-rebase hook script for an example.
</p></div>
1288 <div class=
"paragraph"><p>Upon completion,
<branch
> will be the current branch.
</p></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">
1299 have a wonderful idea
1309 prepare a series for submission
1318 <div class=
"paragraph"><p>where point
2. consists of several instances of
</p></div>
1319 <div class=
"olist loweralpha"><ol class=
"loweralpha">
1324 <div class=
"olist arabic"><ol class=
"arabic">
1327 finish something worthy of a commit
1341 <div class=
"olist arabic"><ol class=
"arabic">
1344 realize that something does not work
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
<after-this-commit
></tt></pre>
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
’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
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
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>
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">
1414 ---o---O---P---Q
</tt></pre>
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>
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
1432 pick c0ffeee The oneline of the next commit
1433 edit deadbab The oneline of the commit after
1434 exec cd subdir; make test
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",
">",
";" …). The command is run from
1443 the root of the working tree.
</p></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>
1454 Start an interactive rebase with
<tt>git rebase -i
<commit
>^
</tt>, where
1455 <commit
> is the commit you want to split. In fact, any commit range
1456 will do, as long as it contains that commit.
1461 Mark the commit you want to split with the action
"edit".
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.
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.
1480 Commit the now-current index with whatever commit message is appropriate
1486 Repeat the last two steps until your working tree is clean.
1491 Continue the rebase with
<tt>git rebase --continue
</tt>.
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>
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
’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>
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>
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>
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.
1550 This happens if the
<em>subsystem
</em> rebase was a simple rebase and
1554 <dt class=
"hdlist1">
1555 Hard case: The changes are not the same.
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>.
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
’re on
<em>topic
</em>)
</p></div>
1573 <div class=
"listingblock">
1574 <div class=
"content">
1575 <pre><tt> $ git rebase subsystem
</tt></pre>
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>
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">
1592 <div class=
"title">Note
</div>
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>
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>
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>.)
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>.
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>
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>
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>
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>
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">
1650 1 ---
2 ---
4 ---
5</tt></pre>
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>
1658 <div id=
"footnotes"><hr /></div>
1660 <div id=
"footer-text">
1661 Last updated
2011-
09-
21 23:
01:
14 PDT