1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <article lang="en" id="git-rebase(1)">
\r
6 <title>git-rebase(1)</title>
\r
8 <primary>git-rebase(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-rebase - Forward-port local commits to the updated upstream head</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git rebase</emphasis> [-i | --interactive] [options] [--onto <newbase>]
\r
19 [<upstream>] [<branch>]
\r
20 <emphasis>git rebase</emphasis> [-i | --interactive] [options] --onto <newbase>
\r
21 --root [<branch>]
\r
22 <emphasis>git rebase</emphasis> --continue | --skip | --abort</literallayout>
\r
25 <simplesect id="_description">
\r
26 <title>DESCRIPTION</title>
\r
27 <simpara>If <branch> is specified, <emphasis>git rebase</emphasis> will perform an automatic
\r
28 <emphasis>git checkout <branch></emphasis> before doing anything else. Otherwise
\r
29 it remains on the current branch.</simpara>
\r
30 <simpara>If <upstream> is not specified, the upstream configured in
\r
31 branch.<name>.remote and branch.<name>.merge options will be used; see
\r
32 <xref linkend="git-config(1)" /> for details. If you are currently not on any
\r
33 branch or if the current branch does not have a configured upstream,
\r
34 the rebase will abort.</simpara>
\r
35 <simpara>All changes made by commits in the current branch but that are not
\r
36 in <upstream> are saved to a temporary area. This is the same set
\r
37 of commits that would be shown by <emphasis>git log <upstream>..HEAD</emphasis> (or
\r
38 <emphasis>git log HEAD</emphasis>, if --root is specified).</simpara>
\r
39 <simpara>The current branch is reset to <upstream>, or <newbase> if the
\r
40 --onto option was supplied. This has the exact same effect as
\r
41 <emphasis>git reset --hard <upstream></emphasis> (or <newbase>). ORIG_HEAD is set
\r
42 to point at the tip of the branch before the reset.</simpara>
\r
43 <simpara>The commits that were previously saved into the temporary area are
\r
44 then reapplied to the current branch, one by one, in order. Note that
\r
45 any commits in HEAD which introduce the same textual changes as a commit
\r
46 in HEAD..<upstream> are omitted (i.e., a patch already accepted upstream
\r
47 with a different commit message or timestamp will be skipped).</simpara>
\r
48 <simpara>It is possible that a merge failure will prevent this process from being
\r
49 completely automatic. You will have to resolve any such merge failure
\r
50 and run <emphasis>git rebase --continue</emphasis>. Another option is to bypass the commit
\r
51 that caused the merge failure with <emphasis>git rebase --skip</emphasis>. To check out the
\r
52 original <branch> and remove the .git/rebase-apply working files, use the
\r
53 command <emphasis>git rebase --abort</emphasis> instead.</simpara>
\r
54 <simpara>Assume the following history exists and the current branch is "topic":</simpara>
\r
55 <screen> A---B---C topic
\r
57 D---E---F---G master</screen>
\r
58 <simpara>From this point, the result of either of the following commands:</simpara>
\r
59 <literallayout class="monospaced">git rebase master
\r
60 git rebase master topic</literallayout>
\r
61 <simpara>would be:</simpara>
\r
62 <screen> A'--B'--C' topic
\r
64 D---E---F---G master</screen>
\r
65 <simpara><emphasis role="strong">NOTE:</emphasis> The latter form is just a short-hand of <emphasis>git checkout topic</emphasis>
\r
66 followed by <emphasis>git rebase master</emphasis>. When rebase exits <emphasis>topic</emphasis> will
\r
67 remain the checked-out branch.</simpara>
\r
68 <simpara>If the upstream branch already contains a change you have made (e.g.,
\r
69 because you mailed a patch which was applied upstream), then that commit
\r
70 will be skipped. For example, running git rebase master` on the
\r
71 following history (in which A and A introduce the same set of changes,
\r
72 but have different committer information):</simpara>
\r
73 <screen> A---B---C topic
\r
75 D---E---A'---F master</screen>
\r
76 <simpara>will result in:</simpara>
\r
77 <screen> B'---C' topic
\r
79 D---E---A'---F master</screen>
\r
80 <simpara>Here is how you would transplant a topic branch based on one
\r
81 branch to another, to pretend that you forked the topic branch
\r
82 from the latter branch, using <emphasis>rebase --onto</emphasis>.</simpara>
\r
83 <simpara>First let's assume your <emphasis>topic</emphasis> is based on branch <emphasis>next</emphasis>.
\r
84 For example, a feature developed in <emphasis>topic</emphasis> depends on some
\r
85 functionality which is found in <emphasis>next</emphasis>.</simpara>
\r
86 <screen> o---o---o---o---o master
\r
88 o---o---o---o---o next
\r
90 o---o---o topic</screen>
\r
91 <simpara>We want to make <emphasis>topic</emphasis> forked from branch <emphasis>master</emphasis>; for example,
\r
92 because the functionality on which <emphasis>topic</emphasis> depends was merged into the
\r
93 more stable <emphasis>master</emphasis> branch. We want our tree to look like this:</simpara>
\r
94 <screen> o---o---o---o---o master
\r
98 o---o---o---o---o next</screen>
\r
99 <simpara>We can get this using the following command:</simpara>
\r
100 <literallayout class="monospaced">git rebase --onto master next topic</literallayout>
\r
101 <simpara>Another example of --onto option is to rebase part of a
\r
102 branch. If we have the following situation:</simpara>
\r
103 <screen> H---I---J topicB
\r
107 A---B---C---D master</screen>
\r
108 <simpara>then the command</simpara>
\r
109 <literallayout class="monospaced">git rebase --onto master topicA topicB</literallayout>
\r
110 <simpara>would result in:</simpara>
\r
111 <screen> H'--I'--J' topicB
\r
115 A---B---C---D master</screen>
\r
116 <simpara>This is useful when topicB does not depend on topicA.</simpara>
\r
117 <simpara>A range of commits could also be removed with rebase. If we have
\r
118 the following situation:</simpara>
\r
119 <screen> E---F---G---H---I---J topicA</screen>
\r
120 <simpara>then the command</simpara>
\r
121 <literallayout class="monospaced">git rebase --onto topicA~5 topicA~3 topicA</literallayout>
\r
122 <simpara>would result in the removal of commits F and G:</simpara>
\r
123 <screen> E---H'---I'---J' topicA</screen>
\r
124 <simpara>This is useful if F and G were flawed in some way, or should not be
\r
125 part of topicA. Note that the argument to --onto and the <upstream>
\r
126 parameter can be any valid commit-ish.</simpara>
\r
127 <simpara>In case of conflict, <emphasis>git rebase</emphasis> will stop at the first problematic commit
\r
128 and leave conflict markers in the tree. You can use <emphasis>git diff</emphasis> to locate
\r
129 the markers (<<<<<<) and make edits to resolve the conflict. For each
\r
130 file you edit, you need to tell git that the conflict has been resolved,
\r
131 typically this would be done with</simpara>
\r
132 <literallayout class="monospaced">git add <filename></literallayout>
\r
133 <simpara>After resolving the conflict manually and updating the index with the
\r
134 desired resolution, you can continue the rebasing process with</simpara>
\r
135 <literallayout class="monospaced">git rebase --continue</literallayout>
\r
136 <simpara>Alternatively, you can undo the <emphasis>git rebase</emphasis> with</simpara>
\r
137 <literallayout class="monospaced">git rebase --abort</literallayout>
\r
139 <simplesect id="_configuration">
\r
140 <title>CONFIGURATION</title>
\r
148 Whether to show a diffstat of what changed upstream since the last
\r
149 rebase. False by default.
\r
159 If set to true enable <emphasis>--autosquash</emphasis> option by default.
\r
165 <simplesect id="_options">
\r
166 <title>OPTIONS</title>
\r
174 Starting point at which to create the new commits. If the
\r
175 --onto option is not specified, the starting point is
\r
176 <upstream>. May be any valid commit, and not just an
\r
177 existing branch name.
\r
179 <simpara>As a special case, you may use "A...B" as a shortcut for the
\r
180 merge base of A and B if there is exactly one merge base. You can
\r
181 leave out at most one of A and B, in which case it defaults to HEAD.</simpara>
\r
190 Upstream branch to compare against. May be any valid commit,
\r
191 not just an existing branch name. Defaults to the configured
\r
192 upstream for the current branch.
\r
202 Working branch; defaults to HEAD.
\r
212 Restart the rebasing process after having resolved a merge conflict.
\r
222 Abort the rebase operation and reset HEAD to the original
\r
223 branch. If <branch> was provided when the rebase operation was
\r
224 started, then HEAD will be reset to <branch>. Otherwise HEAD
\r
225 will be reset to where it was when the rebase operation was
\r
236 Restart the rebasing process by skipping the current patch.
\r
249 Use merging strategies to rebase. When the recursive (default) merge
\r
250 strategy is used, this allows rebase to be aware of renames on the
\r
253 <simpara>Note that a rebase merge works by replaying each commit from the working
\r
254 branch on top of the <upstream> branch. Because of this, when a merge
\r
255 conflict happens, the side reported as <emphasis>ours</emphasis> is the so-far rebased
\r
256 series, starting with <upstream>, and <emphasis>theirs</emphasis> is the working branch. In
\r
257 other words, the sides are swapped.</simpara>
\r
262 -s <strategy>
\r
265 --strategy=<strategy>
\r
269 Use the given merge strategy.
\r
270 If there is no <emphasis>-s</emphasis> option <emphasis>git merge-recursive</emphasis> is used
\r
271 instead. This implies --merge.
\r
273 <simpara>Because <emphasis>git rebase</emphasis> replays each commit from the working branch
\r
274 on top of the <upstream> branch using the given strategy, using
\r
275 the <emphasis>ours</emphasis> strategy simply discards all patches from the <branch>,
\r
276 which makes little sense.</simpara>
\r
281 -X <strategy-option>
\r
284 --strategy-option=<strategy-option>
\r
288 Pass the <strategy-option> through to the merge strategy.
\r
289 This implies <emphasis>--merge</emphasis> and, if no strategy has been
\r
290 specified, <emphasis>-s recursive</emphasis>. Note the reversal of <emphasis>ours</emphasis> and
\r
291 <emphasis>theirs</emphasis> as noted in above for the <emphasis>-m</emphasis> option.
\r
304 Be quiet. Implies --no-stat.
\r
317 Be verbose. Implies --stat.
\r
327 Show a diffstat of what changed upstream since the last rebase. The
\r
328 diffstat is also controlled by the configuration option rebase.stat.
\r
341 Do not show a diffstat as part of the rebase process.
\r
351 This option bypasses the pre-rebase hook. See also <xref linkend="githooks(5)" />.
\r
361 Allows the pre-rebase hook to run, which is the default. This option can
\r
362 be used to override --no-verify. See also <xref linkend="githooks(5)" />.
\r
372 Ensure at least <n> lines of surrounding context match before
\r
373 and after each change. When fewer lines of surrounding
\r
374 context exist they all must match. By default no context is
\r
388 Force the rebase even if the current branch is a descendant
\r
389 of the commit you are rebasing onto. Normally non-interactive rebase will
\r
390 exit with the message "Current branch is up to date" in such a
\r
392 Incompatible with the --interactive option.
\r
394 <simpara>You may find this (or --no-ff with an interactive rebase) helpful after
\r
395 reverting a topic branch merge, as this option recreates the topic branch with
\r
396 fresh commits so it can be remerged successfully without needing to "revert
\r
397 the reversion" (see the
\r
398 link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for details).</simpara>
\r
403 --ignore-whitespace
\r
406 --whitespace=<option>
\r
410 These flag are passed to the <emphasis>git apply</emphasis> program
\r
411 (see <xref linkend="git-apply(1)" />) that applies the patch.
\r
412 Incompatible with the --interactive option.
\r
418 --committer-date-is-author-date
\r
425 These flags are passed to <emphasis>git am</emphasis> to easily change the dates
\r
426 of the rebased commits (see <xref linkend="git-am(1)" />).
\r
427 Incompatible with the --interactive option.
\r
440 Make a list of the commits which are about to be rebased. Let the
\r
441 user edit that list before rebasing. This mode can also be used to
\r
442 split commits (see SPLITTING COMMITS below).
\r
455 Instead of ignoring merges, try to recreate them.
\r
457 <simpara>This uses the <emphasis>--interactive</emphasis> machinery internally, but combining it
\r
458 with the <emphasis>--interactive</emphasis> option explicitly is generally not a good
\r
459 idea unless you know what you are doing (see BUGS below).</simpara>
\r
468 Rebase all commits reachable from <branch>, instead of
\r
469 limiting them with an <upstream>. This allows you to rebase
\r
470 the root commit(s) on a branch. Must be used with --onto, and
\r
471 will skip changes already contained in <newbase> (instead of
\r
472 <upstream>). When used together with --preserve-merges, <emphasis>all</emphasis>
\r
473 root commits will be rewritten to have <newbase> as parent
\r
487 When the commit log message begins with "squash! …" (or
\r
488 "fixup! …"), and there is a commit whose title begins with
\r
489 the same …, automatically modify the todo list of rebase -i
\r
490 so that the commit marked for squashing comes right after the
\r
491 commit to be modified, and change the action of the moved
\r
492 commit from <emphasis>pick</emphasis> to <emphasis>squash</emphasis> (or <emphasis>fixup</emphasis>).
\r
494 <simpara>This option is only valid when the <emphasis>--interactive</emphasis> option is used.</simpara>
\r
495 <simpara>If the <emphasis>--autosquash</emphasis> option is enabled by default using the
\r
496 configuration variable <emphasis>rebase.autosquash</emphasis>, this option can be
\r
497 used to override and disable this setting.</simpara>
\r
506 With --interactive, cherry-pick all rebased commits instead of
\r
507 fast-forwarding over the unchanged ones. This ensures that the
\r
508 entire history of the rebased branch is composed of new commits.
\r
510 <simpara>Without --interactive, this is a synonym for --force-rebase.</simpara>
\r
511 <simpara>You may find this helpful after reverting a topic branch merge, as this option
\r
512 recreates the topic branch with fresh commits so it can be remerged
\r
513 successfully without needing to "revert the reversion" (see the
\r
514 link:howto/revert-a-faulty-merge.txt[revert-a-faulty-merge How-To] for details).</simpara>
\r
519 <simplesect id="_merge_strategies">
\r
520 <title>MERGE STRATEGIES</title>
\r
521 <simpara>The merge mechanism (<emphasis>git-merge</emphasis> and <emphasis>git-pull</emphasis> commands) allows the
\r
522 backend <emphasis>merge strategies</emphasis> to be chosen with <emphasis>-s</emphasis> option. Some strategies
\r
523 can also take their own options, which can be passed by giving <emphasis>-X<option></emphasis>
\r
524 arguments to <emphasis>git-merge</emphasis> and/or <emphasis>git-pull</emphasis>.</simpara>
\r
532 This can only resolve two heads (i.e. the current branch
\r
533 and another branch you pulled from) using a 3-way merge
\r
534 algorithm. It tries to carefully detect criss-cross
\r
535 merge ambiguities and is considered generally safe and
\r
546 This can only resolve two heads using a 3-way merge
\r
547 algorithm. When there is more than one common
\r
548 ancestor that can be used for 3-way merge, it creates a
\r
549 merged tree of the common ancestors and uses that as
\r
550 the reference tree for the 3-way merge. This has been
\r
551 reported to result in fewer merge conflicts without
\r
552 causing mis-merges by tests done on actual merge commits
\r
553 taken from Linux 2.6 kernel development history.
\r
554 Additionally this can detect and handle merges involving
\r
555 renames. This is the default merge strategy when
\r
556 pulling or merging one branch.
\r
558 <simpara>The <emphasis>recursive</emphasis> strategy can take the following options:</simpara>
\r
566 This option forces conflicting hunks to be auto-resolved cleanly by
\r
567 favoring <emphasis>our</emphasis> version. Changes from the other tree that do not
\r
568 conflict with our side are reflected to the merge result.
\r
570 <simpara>This should not be confused with the <emphasis>ours</emphasis> merge strategy, which does not
\r
571 even look at what the other tree contains at all. It discards everything
\r
572 the other tree did, declaring <emphasis>our</emphasis> history contains all that happened in it.</simpara>
\r
581 This is opposite of <emphasis>ours</emphasis>.
\r
591 With this option, <emphasis>merge-recursive</emphasis> spends a little extra time
\r
592 to avoid mismerges that sometimes occur due to unimportant
\r
593 matching lines (e.g., braces from distinct functions). Use
\r
594 this when the branches to be merged have diverged wildly.
\r
595 See also <xref linkend="git-diff(1)" /> <emphasis>--patience</emphasis>.
\r
601 ignore-space-change
\r
607 ignore-space-at-eol
\r
611 Treats lines with the indicated type of whitespace change as
\r
612 unchanged for the sake of a three-way merge. Whitespace
\r
613 changes mixed with other changes to a line are not ignored.
\r
614 See also <xref linkend="git-diff(1)" /> <emphasis>-b</emphasis>, <emphasis>-w</emphasis>, and
\r
615 <emphasis>--ignore-space-at-eol</emphasis>.
\r
620 If <emphasis>their</emphasis> version only introduces whitespace changes to a line,
\r
621 <emphasis>our</emphasis> version is used;
\r
626 If <emphasis>our</emphasis> version introduces whitespace changes but <emphasis>their</emphasis>
\r
627 version includes a substantial change, <emphasis>their</emphasis> version is used;
\r
632 Otherwise, the merge proceeds in the usual way.
\r
644 This runs a virtual check-out and check-in of all three stages
\r
645 of a file when resolving a three-way merge. This option is
\r
646 meant to be used when merging branches with different clean
\r
647 filters or end-of-line normalization rules. See "Merging
\r
648 branches with differing checkin/checkout attributes" in
\r
649 <xref linkend="gitattributes(5)" /> for details.
\r
659 Disables the <emphasis>renormalize</emphasis> option. This overrides the
\r
660 <emphasis>merge.renormalize</emphasis> configuration variable.
\r
666 rename-threshold=<n>
\r
670 Controls the similarity threshold used for rename detection.
\r
671 See also <xref linkend="git-diff(1)" /> <emphasis>-M</emphasis>.
\r
677 subtree[=<path>]
\r
681 This option is a more advanced form of <emphasis>subtree</emphasis> strategy, where
\r
682 the strategy makes a guess on how two trees must be shifted to
\r
683 match with each other when merging. Instead, the specified path
\r
684 is prefixed (or stripped from the beginning) to make the shape of
\r
685 two trees to match.
\r
698 This resolves cases with more than two heads, but refuses to do
\r
699 a complex merge that needs manual resolution. It is
\r
700 primarily meant to be used for bundling topic branch
\r
701 heads together. This is the default merge strategy when
\r
702 pulling or merging more than one branch.
\r
712 This resolves any number of heads, but the resulting tree of the
\r
713 merge is always that of the current branch head, effectively
\r
714 ignoring all changes from all other branches. It is meant to
\r
715 be used to supersede old development history of side
\r
716 branches. Note that this is different from the -Xours option to
\r
717 the <emphasis>recursive</emphasis> merge strategy.
\r
727 This is a modified recursive strategy. When merging trees A and
\r
728 B, if B corresponds to a subtree of A, B is first adjusted to
\r
729 match the tree structure of A, instead of reading the trees at
\r
730 the same level. This adjustment is also done to the common
\r
737 <simplesect id="_notes">
\r
738 <title>NOTES</title>
\r
739 <simpara>You should understand the implications of using <emphasis>git rebase</emphasis> on a
\r
740 repository that you share. See also RECOVERING FROM UPSTREAM REBASE
\r
742 <simpara>When the git-rebase command is run, it will first execute a "pre-rebase"
\r
743 hook if one exists. You can use this hook to do sanity checks and
\r
744 reject the rebase if it isn't appropriate. Please see the template
\r
745 pre-rebase hook script for an example.</simpara>
\r
746 <simpara>Upon completion, <branch> will be the current branch.</simpara>
\r
748 <simplesect id="_interactive_mode">
\r
749 <title>INTERACTIVE MODE</title>
\r
750 <simpara>Rebasing interactively means that you have a chance to edit the commits
\r
751 which are rebased. You can reorder the commits, and you can
\r
752 remove them (weeding out bad or otherwise unwanted patches).</simpara>
\r
753 <simpara>The interactive mode is meant for this type of workflow:</simpara>
\r
754 <orderedlist numeration="arabic">
\r
757 have a wonderful idea
\r
767 prepare a series for submission
\r
776 <simpara>where point 2. consists of several instances of</simpara>
\r
777 <simpara>a) regular use</simpara>
\r
778 <orderedlist numeration="arabic">
\r
781 finish something worthy of a commit
\r
790 <simpara>b) independent fixup</simpara>
\r
791 <orderedlist numeration="arabic">
\r
794 realize that something does not work
\r
808 <simpara>Sometimes the thing fixed in b.2. cannot be amended to the not-quite
\r
809 perfect commit it fixes, because that commit is buried deeply in a
\r
810 patch series. That is exactly what interactive rebase is for: use it
\r
811 after plenty of "a"s and "b"s, by rearranging and editing
\r
812 commits, and squashing multiple commits into one.</simpara>
\r
813 <simpara>Start it with the last commit you want to retain as-is:</simpara>
\r
814 <literallayout class="monospaced">git rebase -i <after-this-commit></literallayout>
\r
815 <simpara>An editor will be fired up with all the commits in your current branch
\r
816 (ignoring merge commits), which come after the given commit. You can
\r
817 reorder the commits in this list to your heart's content, and you can
\r
818 remove them. The list looks more or less like this:</simpara>
\r
819 <screen>pick deadbee The oneline of this commit
\r
820 pick fa1afe1 The oneline of the next commit
\r
822 <simpara>The oneline descriptions are purely for your pleasure; <emphasis>git rebase</emphasis> will
\r
823 not look at them but at the commit names ("deadbee" and "fa1afe1" in this
\r
824 example), so do not delete or edit the names.</simpara>
\r
825 <simpara>By replacing the command "pick" with the command "edit", you can tell
\r
826 <emphasis>git rebase</emphasis> to stop after applying that commit, so that you can edit
\r
827 the files and/or the commit message, amend the commit, and continue
\r
828 rebasing.</simpara>
\r
829 <simpara>If you just want to edit the commit message for a commit, replace the
\r
830 command "pick" with the command "reword".</simpara>
\r
831 <simpara>If you want to fold two or more commits into one, replace the command
\r
832 "pick" for the second and subsequent commits with "squash" or "fixup".
\r
833 If the commits had different authors, the folded commit will be
\r
834 attributed to the author of the first commit. The suggested commit
\r
835 message for the folded commit is the concatenation of the commit
\r
836 messages of the first commit and of those with the "squash" command,
\r
837 but omits the commit messages of commits with the "fixup" command.</simpara>
\r
838 <simpara><emphasis>git rebase</emphasis> will stop when "pick" has been replaced with "edit" or
\r
839 when a command fails due to merge errors. When you are done editing
\r
840 and/or resolving conflicts you can continue with <emphasis>git rebase --continue</emphasis>.</simpara>
\r
841 <simpara>For example, if you want to reorder the last 5 commits, such that what
\r
842 was HEAD~4 becomes the new HEAD. To achieve that, you would call
\r
843 <emphasis>git rebase</emphasis> like this:</simpara>
\r
844 <screen>$ git rebase -i HEAD~5</screen>
\r
845 <simpara>And move the first patch to the end of the list.</simpara>
\r
846 <simpara>You might want to preserve merges, if you have a history like this:</simpara>
\r
851 ---o---O---P---Q</screen>
\r
852 <simpara>Suppose you want to rebase the side branch starting at "A" to "Q". Make
\r
853 sure that the current HEAD is "B", and call</simpara>
\r
854 <screen>$ git rebase -i -p --onto Q O</screen>
\r
855 <simpara>Reordering and editing commits usually creates untested intermediate
\r
856 steps. You may want to check that your history editing did not break
\r
857 anything by running a test, or at least recompiling at intermediate
\r
858 points in history by using the "exec" command (shortcut "x"). You may
\r
859 do so by creating a todo list like this one:</simpara>
\r
860 <screen>pick deadbee Implement feature XXX
\r
861 fixup f1a5c00 Fix to feature XXX
\r
863 pick c0ffeee The oneline of the next commit
\r
864 edit deadbab The oneline of the commit after
\r
865 exec cd subdir; make test
\r
867 <simpara>The interactive rebase will stop when a command fails (i.e. exits with
\r
868 non-0 status) to give you an opportunity to fix the problem. You can
\r
869 continue with <emphasis>git rebase --continue</emphasis>.</simpara>
\r
870 <simpara>The "exec" command launches the command in a shell (the one specified
\r
871 in <emphasis>$SHELL</emphasis>, or the default shell if <emphasis>$SHELL</emphasis> is not set), so you can
\r
872 use shell features (like "cd", ">", ";" …). The command is run from
\r
873 the root of the working tree.</simpara>
\r
875 <simplesect id="_splitting_commits">
\r
876 <title>SPLITTING COMMITS</title>
\r
877 <simpara>In interactive mode, you can mark commits with the action "edit". However,
\r
878 this does not necessarily mean that <emphasis>git rebase</emphasis> expects the result of this
\r
879 edit to be exactly one commit. Indeed, you can undo the commit, or you can
\r
880 add other commits. This can be used to split a commit into two:</simpara>
\r
884 Start an interactive rebase with <emphasis>git rebase -i <commit>^</emphasis>, where
\r
885 <commit> is the commit you want to split. In fact, any commit range
\r
886 will do, as long as it contains that commit.
\r
891 Mark the commit you want to split with the action "edit".
\r
896 When it comes to editing that commit, execute <emphasis>git reset HEAD^</emphasis>. The
\r
897 effect is that the HEAD is rewound by one, and the index follows suit.
\r
898 However, the working tree stays the same.
\r
903 Now add the changes to the index that you want to have in the first
\r
904 commit. You can use <emphasis>git add</emphasis> (possibly interactively) or
\r
905 <emphasis>git gui</emphasis> (or both) to do that.
\r
910 Commit the now-current index with whatever commit message is appropriate
\r
916 Repeat the last two steps until your working tree is clean.
\r
921 Continue the rebase with <emphasis>git rebase --continue</emphasis>.
\r
925 <simpara>If you are not absolutely sure that the intermediate revisions are
\r
926 consistent (they compile, pass the testsuite, etc.) you should use
\r
927 <emphasis>git stash</emphasis> to stash away the not-yet-committed changes
\r
928 after each commit, test, and amend the commit if fixes are necessary.</simpara>
\r
930 <simplesect id="_recovering_from_upstream_rebase">
\r
931 <title>RECOVERING FROM UPSTREAM REBASE</title>
\r
932 <simpara>Rebasing (or any other form of rewriting) a branch that others have
\r
933 based work on is a bad idea: anyone downstream of it is forced to
\r
934 manually fix their history. This section explains how to do the fix
\r
935 from the downstream's point of view. The real fix, however, would be
\r
936 to avoid rebasing the upstream in the first place.</simpara>
\r
937 <simpara>To illustrate, suppose you are in a situation where someone develops a
\r
938 <emphasis>subsystem</emphasis> branch, and you are working on a <emphasis>topic</emphasis> that is dependent
\r
939 on this <emphasis>subsystem</emphasis>. You might end up with a history like the
\r
940 following:</simpara>
\r
941 <screen> o---o---o---o---o---o---o---o---o master
\r
943 o---o---o---o---o subsystem
\r
945 *---*---* topic</screen>
\r
946 <simpara>If <emphasis>subsystem</emphasis> is rebased against <emphasis>master</emphasis>, the following happens:</simpara>
\r
947 <screen> o---o---o---o---o---o---o---o master
\r
949 o---o---o---o---o o'--o'--o'--o'--o' subsystem
\r
951 *---*---* topic</screen>
\r
952 <simpara>If you now continue development as usual, and eventually merge <emphasis>topic</emphasis>
\r
953 to <emphasis>subsystem</emphasis>, the commits from <emphasis>subsystem</emphasis> will remain duplicated forever:</simpara>
\r
954 <screen> o---o---o---o---o---o---o---o master
\r
956 o---o---o---o---o o'--o'--o'--o'--o'--M subsystem
\r
958 *---*---*-..........-*--* topic</screen>
\r
959 <simpara>Such duplicates are generally frowned upon because they clutter up
\r
960 history, making it harder to follow. To clean things up, you need to
\r
961 transplant the commits on <emphasis>topic</emphasis> to the new <emphasis>subsystem</emphasis> tip, i.e.,
\r
962 rebase <emphasis>topic</emphasis>. This becomes a ripple effect: anyone downstream from
\r
963 <emphasis>topic</emphasis> is forced to rebase too, and so on!</simpara>
\r
964 <simpara>There are two kinds of fixes, discussed in the following subsections:</simpara>
\r
968 Easy case: The changes are literally the same.
\r
972 This happens if the <emphasis>subsystem</emphasis> rebase was a simple rebase and
\r
979 Hard case: The changes are not the same.
\r
983 This happens if the <emphasis>subsystem</emphasis> rebase had conflicts, or used
\r
984 <emphasis>--interactive</emphasis> to omit, edit, squash, or fixup commits; or
\r
985 if the upstream used one of <emphasis>commit --amend</emphasis>, <emphasis>reset</emphasis>, or
\r
986 <emphasis>filter-branch</emphasis>.
\r
991 <section id="_the_easy_case">
\r
992 <title>The easy case</title>
\r
993 <simpara>Only works if the changes (patch IDs based on the diff contents) on
\r
994 <emphasis>subsystem</emphasis> are literally the same before and after the rebase
\r
995 <emphasis>subsystem</emphasis> did.</simpara>
\r
996 <simpara>In that case, the fix is easy because <emphasis>git rebase</emphasis> knows to skip
\r
997 changes that are already present in the new upstream. So if you say
\r
998 (assuming you're on <emphasis>topic</emphasis>)</simpara>
\r
999 <screen> $ git rebase subsystem</screen>
\r
1000 <simpara>you will end up with the fixed history</simpara>
\r
1001 <screen> o---o---o---o---o---o---o---o master
\r
1003 o'--o'--o'--o'--o' subsystem
\r
1005 *---*---* topic</screen>
\r
1007 <section id="_the_hard_case">
\r
1008 <title>The hard case</title>
\r
1009 <simpara>Things get more complicated if the <emphasis>subsystem</emphasis> changes do not exactly
\r
1010 correspond to the ones before the rebase.</simpara>
\r
1011 <note><simpara>While an "easy case recovery" sometimes appears to be successful
\r
1012 even in the hard case, it may have unintended consequences. For
\r
1013 example, a commit that was removed via <emphasis>git rebase
\r
1014 --interactive</emphasis> will be <emphasis role="strong">resurrected</emphasis>!</simpara></note>
\r
1015 <simpara>The idea is to manually tell <emphasis>git rebase</emphasis> "where the old <emphasis>subsystem</emphasis>
\r
1016 ended and your <emphasis>topic</emphasis> began", that is, what the old merge-base
\r
1017 between them was. You will have to find a way to name the last commit
\r
1018 of the old <emphasis>subsystem</emphasis>, for example:</simpara>
\r
1022 With the <emphasis>subsystem</emphasis> reflog: after <emphasis>git fetch</emphasis>, the old tip of
\r
1023 <emphasis>subsystem</emphasis> is at <emphasis>subsystem@{1}</emphasis>. Subsequent fetches will
\r
1024 increase the number. (See <xref linkend="git-reflog(1)" />.)
\r
1029 Relative to the tip of <emphasis>topic</emphasis>: knowing that your <emphasis>topic</emphasis> has three
\r
1030 commits, the old tip of <emphasis>subsystem</emphasis> must be <emphasis>topic~3</emphasis>.
\r
1034 <simpara>You can then transplant the old <emphasis>subsystem..topic</emphasis> to the new tip by
\r
1035 saying (for the reflog case, and assuming you are on <emphasis>topic</emphasis> already):</simpara>
\r
1036 <screen> $ git rebase --onto subsystem subsystem@{1}</screen>
\r
1037 <simpara>The ripple effect of a "hard case" recovery is especially bad:
\r
1038 <emphasis>everyone</emphasis> downstream from <emphasis>topic</emphasis> will now have to perform a "hard
\r
1039 case" recovery too!</simpara>
\r
1042 <simplesect id="_bugs">
\r
1043 <title>BUGS</title>
\r
1044 <simpara>The todo list presented by <emphasis>--preserve-merges --interactive</emphasis> does not
\r
1045 represent the topology of the revision graph. Editing commits and
\r
1046 rewording their commit messages should work fine, but attempts to
\r
1047 reorder commits tend to produce counterintuitive results.</simpara>
\r
1048 <simpara>For example, an attempt to rearrange</simpara>
\r
1049 <screen>1 --- 2 --- 3 --- 4 --- 5</screen>
\r
1050 <simpara>to</simpara>
\r
1051 <screen>1 --- 2 --- 4 --- 3 --- 5</screen>
\r
1052 <simpara>by moving the "pick 4" line will result in the following history:</simpara>
\r
1055 1 --- 2 --- 4 --- 5</screen>
\r
1057 <simplesect id="_git">
\r
1058 <title>GIT</title>
\r
1059 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r