1GIT-REBASE(1)                     Git Manual                     GIT-REBASE(1)
2
3
4

NAME

6       git-rebase - Reapply commits on top of another base tip
7

SYNOPSIS

9       git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
10               [<upstream> [<branch>]]
11       git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
12               --root [<branch>]
13       git rebase --continue | --skip | --abort | --quit | --edit-todo | --show-current-patch
14
15

DESCRIPTION

17       If <branch> is specified, git rebase will perform an automatic git
18       checkout <branch> before doing anything else. Otherwise it remains on
19       the current branch.
20
21       If <upstream> is not specified, the upstream configured in
22       branch.<name>.remote and branch.<name>.merge options will be used (see
23       git-config(1) for details) and the --fork-point option is assumed. If
24       you are currently not on any branch or if the current branch does not
25       have a configured upstream, the rebase will abort.
26
27       All changes made by commits in the current branch but that are not in
28       <upstream> are saved to a temporary area. This is the same set of
29       commits that would be shown by git log <upstream>..HEAD; or by git log
30       'fork_point'..HEAD, if --fork-point is active (see the description on
31       --fork-point below); or by git log HEAD, if the --root option is
32       specified.
33
34       The current branch is reset to <upstream>, or <newbase> if the --onto
35       option was supplied. This has the exact same effect as git reset --hard
36       <upstream> (or <newbase>). ORIG_HEAD is set to point at the tip of the
37       branch before the reset.
38
39       The commits that were previously saved into the temporary area are then
40       reapplied to the current branch, one by one, in order. Note that any
41       commits in HEAD which introduce the same textual changes as a commit in
42       HEAD..<upstream> are omitted (i.e., a patch already accepted upstream
43       with a different commit message or timestamp will be skipped).
44
45       It is possible that a merge failure will prevent this process from
46       being completely automatic. You will have to resolve any such merge
47       failure and run git rebase --continue. Another option is to bypass the
48       commit that caused the merge failure with git rebase --skip. To check
49       out the original <branch> and remove the .git/rebase-apply working
50       files, use the command git rebase --abort instead.
51
52       Assume the following history exists and the current branch is "topic":
53
54                     A---B---C topic
55                    /
56               D---E---F---G master
57
58
59       From this point, the result of either of the following commands:
60
61           git rebase master
62           git rebase master topic
63
64       would be:
65
66                             A'--B'--C' topic
67                            /
68               D---E---F---G master
69
70
71       NOTE: The latter form is just a short-hand of git checkout topic
72       followed by git rebase master. When rebase exits topic will remain the
73       checked-out branch.
74
75       If the upstream branch already contains a change you have made (e.g.,
76       because you mailed a patch which was applied upstream), then that
77       commit will be skipped. For example, running git rebase master on the
78       following history (in which A' and A introduce the same set of changes,
79       but have different committer information):
80
81                     A---B---C topic
82                    /
83               D---E---A'---F master
84
85
86       will result in:
87
88                              B'---C' topic
89                             /
90               D---E---A'---F master
91
92
93       Here is how you would transplant a topic branch based on one branch to
94       another, to pretend that you forked the topic branch from the latter
95       branch, using rebase --onto.
96
97       First let’s assume your topic is based on branch next. For example, a
98       feature developed in topic depends on some functionality which is found
99       in next.
100
101               o---o---o---o---o  master
102                    \
103                     o---o---o---o---o  next
104                                      \
105                                       o---o---o  topic
106
107
108       We want to make topic forked from branch master; for example, because
109       the functionality on which topic depends was merged into the more
110       stable master branch. We want our tree to look like this:
111
112               o---o---o---o---o  master
113                   |            \
114                   |             o'--o'--o'  topic
115                    \
116                     o---o---o---o---o  next
117
118
119       We can get this using the following command:
120
121           git rebase --onto master next topic
122
123       Another example of --onto option is to rebase part of a branch. If we
124       have the following situation:
125
126                                       H---I---J topicB
127                                      /
128                             E---F---G  topicA
129                            /
130               A---B---C---D  master
131
132
133       then the command
134
135           git rebase --onto master topicA topicB
136
137       would result in:
138
139                            H'--I'--J'  topicB
140                           /
141                           | E---F---G  topicA
142                           |/
143               A---B---C---D  master
144
145
146       This is useful when topicB does not depend on topicA.
147
148       A range of commits could also be removed with rebase. If we have the
149       following situation:
150
151               E---F---G---H---I---J  topicA
152
153
154       then the command
155
156           git rebase --onto topicA~5 topicA~3 topicA
157
158       would result in the removal of commits F and G:
159
160               E---H'---I'---J'  topicA
161
162
163       This is useful if F and G were flawed in some way, or should not be
164       part of topicA. Note that the argument to --onto and the <upstream>
165       parameter can be any valid commit-ish.
166
167       In case of conflict, git rebase will stop at the first problematic
168       commit and leave conflict markers in the tree. You can use git diff to
169       locate the markers (<<<<<<) and make edits to resolve the conflict. For
170       each file you edit, you need to tell Git that the conflict has been
171       resolved, typically this would be done with
172
173           git add <filename>
174
175       After resolving the conflict manually and updating the index with the
176       desired resolution, you can continue the rebasing process with
177
178           git rebase --continue
179
180       Alternatively, you can undo the git rebase with
181
182           git rebase --abort
183

CONFIGURATION

185       rebase.useBuiltin
186           Set to false to use the legacy shellscript implementation of git-
187           rebase(1). Is true by default, which means use the built-in rewrite
188           of it in C.
189
190           The C rewrite is first included with Git version 2.20. This option
191           serves an an escape hatch to re-enable the legacy version in case
192           any bugs are found in the rewrite. This option and the shellscript
193           version of git-rebase(1) will be removed in some future release.
194
195           If you find some reason to set this option to false other than
196           one-off testing you should report the behavior difference as a bug
197           in git.
198
199       rebase.stat
200           Whether to show a diffstat of what changed upstream since the last
201           rebase. False by default.
202
203       rebase.autoSquash
204           If set to true enable --autosquash option by default.
205
206       rebase.autoStash
207           When set to true, automatically create a temporary stash entry
208           before the operation begins, and apply it after the operation ends.
209           This means that you can run rebase on a dirty worktree. However,
210           use with care: the final stash application after a successful
211           rebase might result in non-trivial conflicts. This option can be
212           overridden by the --no-autostash and --autostash options of git-
213           rebase(1). Defaults to false.
214
215       rebase.missingCommitsCheck
216           If set to "warn", git rebase -i will print a warning if some
217           commits are removed (e.g. a line was deleted), however the rebase
218           will still proceed. If set to "error", it will print the previous
219           warning and stop the rebase, git rebase --edit-todo can then be
220           used to correct the error. If set to "ignore", no checking is done.
221           To drop a commit without warning or error, use the drop command in
222           the todo list. Defaults to "ignore".
223
224       rebase.instructionFormat
225           A format string, as specified in git-log(1), to be used for the
226           todo list during an interactive rebase. The format will
227           automatically have the long commit hash prepended to the format.
228
229       rebase.abbreviateCommands
230           If set to true, git rebase will use abbreviated command names in
231           the todo list resulting in something like this:
232
233                       p deadbee The oneline of the commit
234                       p fa1afe1 The oneline of the next commit
235                       ...
236
237           instead of:
238
239                       pick deadbee The oneline of the commit
240                       pick fa1afe1 The oneline of the next commit
241                       ...
242
243           Defaults to false.
244
245       rebase.rescheduleFailedExec
246           Automatically reschedule exec commands that failed. This only makes
247           sense in interactive mode (or when an --exec option was provided).
248           This is the same as specifying the --reschedule-failed-exec option.
249

OPTIONS

251       --onto <newbase>
252           Starting point at which to create the new commits. If the --onto
253           option is not specified, the starting point is <upstream>. May be
254           any valid commit, and not just an existing branch name.
255
256           As a special case, you may use "A...B" as a shortcut for the merge
257           base of A and B if there is exactly one merge base. You can leave
258           out at most one of A and B, in which case it defaults to HEAD.
259
260       <upstream>
261           Upstream branch to compare against. May be any valid commit, not
262           just an existing branch name. Defaults to the configured upstream
263           for the current branch.
264
265       <branch>
266           Working branch; defaults to HEAD.
267
268       --continue
269           Restart the rebasing process after having resolved a merge
270           conflict.
271
272       --abort
273           Abort the rebase operation and reset HEAD to the original branch.
274           If <branch> was provided when the rebase operation was started,
275           then HEAD will be reset to <branch>. Otherwise HEAD will be reset
276           to where it was when the rebase operation was started.
277
278       --quit
279           Abort the rebase operation but HEAD is not reset back to the
280           original branch. The index and working tree are also left unchanged
281           as a result.
282
283       --keep-empty
284           Keep the commits that do not change anything from its parents in
285           the result.
286
287           See also INCOMPATIBLE OPTIONS below.
288
289       --allow-empty-message
290           By default, rebasing commits with an empty message will fail. This
291           option overrides that behavior, allowing commits with empty
292           messages to be rebased.
293
294           See also INCOMPATIBLE OPTIONS below.
295
296       --skip
297           Restart the rebasing process by skipping the current patch.
298
299       --edit-todo
300           Edit the todo list during an interactive rebase.
301
302       --show-current-patch
303           Show the current patch in an interactive rebase or when rebase is
304           stopped because of conflicts. This is the equivalent of git show
305           REBASE_HEAD.
306
307       -m, --merge
308           Use merging strategies to rebase. When the recursive (default)
309           merge strategy is used, this allows rebase to be aware of renames
310           on the upstream side.
311
312           Note that a rebase merge works by replaying each commit from the
313           working branch on top of the <upstream> branch. Because of this,
314           when a merge conflict happens, the side reported as ours is the
315           so-far rebased series, starting with <upstream>, and theirs is the
316           working branch. In other words, the sides are swapped.
317
318           See also INCOMPATIBLE OPTIONS below.
319
320       -s <strategy>, --strategy=<strategy>
321           Use the given merge strategy. If there is no -s option git
322           merge-recursive is used instead. This implies --merge.
323
324           Because git rebase replays each commit from the working branch on
325           top of the <upstream> branch using the given strategy, using the
326           ours strategy simply empties all patches from the <branch>, which
327           makes little sense.
328
329           See also INCOMPATIBLE OPTIONS below.
330
331       -X <strategy-option>, --strategy-option=<strategy-option>
332           Pass the <strategy-option> through to the merge strategy. This
333           implies --merge and, if no strategy has been specified, -s
334           recursive. Note the reversal of ours and theirs as noted above for
335           the -m option.
336
337           See also INCOMPATIBLE OPTIONS below.
338
339       -S[<keyid>], --gpg-sign[=<keyid>]
340           GPG-sign commits. The keyid argument is optional and defaults to
341           the committer identity; if specified, it must be stuck to the
342           option without a space.
343
344       -q, --quiet
345           Be quiet. Implies --no-stat.
346
347       -v, --verbose
348           Be verbose. Implies --stat.
349
350       --stat
351           Show a diffstat of what changed upstream since the last rebase. The
352           diffstat is also controlled by the configuration option
353           rebase.stat.
354
355       -n, --no-stat
356           Do not show a diffstat as part of the rebase process.
357
358       --no-verify
359           This option bypasses the pre-rebase hook. See also githooks(5).
360
361       --verify
362           Allows the pre-rebase hook to run, which is the default. This
363           option can be used to override --no-verify. See also githooks(5).
364
365       -C<n>
366           Ensure at least <n> lines of surrounding context match before and
367           after each change. When fewer lines of surrounding context exist
368           they all must match. By default no context is ever ignored.
369
370           See also INCOMPATIBLE OPTIONS below.
371
372       --no-ff, --force-rebase, -f
373           Individually replay all rebased commits instead of fast-forwarding
374           over the unchanged ones. This ensures that the entire history of
375           the rebased branch is composed of new commits.
376
377           You may find this helpful after reverting a topic branch merge, as
378           this option recreates the topic branch with fresh commits so it can
379           be remerged successfully without needing to "revert the reversion"
380           (see the revert-a-faulty-merge How-To[1] for details).
381
382       --fork-point, --no-fork-point
383           Use reflog to find a better common ancestor between <upstream> and
384           <branch> when calculating which commits have been introduced by
385           <branch>.
386
387           When --fork-point is active, fork_point will be used instead of
388           <upstream> to calculate the set of commits to rebase, where
389           fork_point is the result of git merge-base --fork-point <upstream>
390           <branch> command (see git-merge-base(1)). If fork_point ends up
391           being empty, the <upstream> will be used as a fallback.
392
393           If either <upstream> or --root is given on the command line, then
394           the default is --no-fork-point, otherwise the default is
395           --fork-point.
396
397       --ignore-whitespace, --whitespace=<option>
398           These flag are passed to the git apply program (see git-apply(1))
399           that applies the patch.
400
401           See also INCOMPATIBLE OPTIONS below.
402
403       --committer-date-is-author-date, --ignore-date
404           These flags are passed to git am to easily change the dates of the
405           rebased commits (see git-am(1)).
406
407           See also INCOMPATIBLE OPTIONS below.
408
409       --signoff
410           Add a Signed-off-by: trailer to all the rebased commits. Note that
411           if --interactive is given then only commits marked to be picked,
412           edited or reworded will have the trailer added.
413
414           See also INCOMPATIBLE OPTIONS below.
415
416       -i, --interactive
417           Make a list of the commits which are about to be rebased. Let the
418           user edit that list before rebasing. This mode can also be used to
419           split commits (see SPLITTING COMMITS below).
420
421           The commit list format can be changed by setting the configuration
422           option rebase.instructionFormat. A customized instruction format
423           will automatically have the long commit hash prepended to the
424           format.
425
426           See also INCOMPATIBLE OPTIONS below.
427
428       -r, --rebase-merges[=(rebase-cousins|no-rebase-cousins)]
429           By default, a rebase will simply drop merge commits from the todo
430           list, and put the rebased commits into a single, linear branch.
431           With --rebase-merges, the rebase will instead try to preserve the
432           branching structure within the commits that are to be rebased, by
433           recreating the merge commits. Any resolved merge conflicts or
434           manual amendments in these merge commits will have to be
435           resolved/re-applied manually.
436
437           By default, or when no-rebase-cousins was specified, commits which
438           do not have <upstream> as direct ancestor will keep their original
439           branch point, i.e. commits that would be excluded by
440           gitlink:git-log[1]'s --ancestry-path option will keep their
441           original ancestry by default. If the rebase-cousins mode is turned
442           on, such commits are instead rebased onto <upstream> (or <onto>, if
443           specified).
444
445           The --rebase-merges mode is similar in spirit to --preserve-merges,
446           but in contrast to that option works well in interactive rebases:
447           commits can be reordered, inserted and dropped at will.
448
449           It is currently only possible to recreate the merge commits using
450           the recursive merge strategy; Different merge strategies can be
451           used only via explicit exec git merge -s <strategy> [...]
452           commands.
453
454           See also REBASING MERGES and INCOMPATIBLE OPTIONS below.
455
456       -p, --preserve-merges
457           Recreate merge commits instead of flattening the history by
458           replaying commits a merge commit introduces. Merge conflict
459           resolutions or manual amendments to merge commits are not
460           preserved.
461
462           This uses the --interactive machinery internally, but combining it
463           with the --interactive option explicitly is generally not a good
464           idea unless you know what you are doing (see BUGS below).
465
466           See also INCOMPATIBLE OPTIONS below.
467
468       -x <cmd>, --exec <cmd>
469           Append "exec <cmd>" after each line creating a commit in the final
470           history. <cmd> will be interpreted as one or more shell commands.
471           Any command that fails will interrupt the rebase, with exit code 1.
472
473           You may execute several commands by either using one instance of
474           --exec with several commands:
475
476               git rebase -i --exec "cmd1 && cmd2 && ..."
477
478           or by giving more than one --exec:
479
480               git rebase -i --exec "cmd1" --exec "cmd2" --exec ...
481
482           If --autosquash is used, "exec" lines will not be appended for the
483           intermediate commits, and will only appear at the end of each
484           squash/fixup series.
485
486           This uses the --interactive machinery internally, but it can be run
487           without an explicit --interactive.
488
489           See also INCOMPATIBLE OPTIONS below.
490
491       --root
492           Rebase all commits reachable from <branch>, instead of limiting
493           them with an <upstream>. This allows you to rebase the root
494           commit(s) on a branch. When used with --onto, it will skip changes
495           already contained in <newbase> (instead of <upstream>) whereas
496           without --onto it will operate on every change. When used together
497           with both --onto and --preserve-merges, all root commits will be
498           rewritten to have <newbase> as parent instead.
499
500           See also INCOMPATIBLE OPTIONS below.
501
502       --autosquash, --no-autosquash
503           When the commit log message begins with "squash! ..." (or "fixup!
504           ..."), and there is already a commit in the todo list that matches
505           the same ..., automatically modify the todo list of rebase -i so
506           that the commit marked for squashing comes right after the commit
507           to be modified, and change the action of the moved commit from pick
508           to squash (or fixup). A commit matches the ...  if the commit
509           subject matches, or if the ...  refers to the commit’s hash. As a
510           fall-back, partial matches of the commit subject work, too. The
511           recommended way to create fixup/squash commits is by using the
512           --fixup/--squash options of git-commit(1).
513
514           If the --autosquash option is enabled by default using the
515           configuration variable rebase.autoSquash, this option can be used
516           to override and disable this setting.
517
518           See also INCOMPATIBLE OPTIONS below.
519
520       --autostash, --no-autostash
521           Automatically create a temporary stash entry before the operation
522           begins, and apply it after the operation ends. This means that you
523           can run rebase on a dirty worktree. However, use with care: the
524           final stash application after a successful rebase might result in
525           non-trivial conflicts.
526
527       --reschedule-failed-exec, --no-reschedule-failed-exec
528           Automatically reschedule exec commands that failed. This only makes
529           sense in interactive mode (or when an --exec option was provided).
530

INCOMPATIBLE OPTIONS

532       The following options:
533
534       ·   --committer-date-is-author-date
535
536       ·   --ignore-date
537
538       ·   --whitespace
539
540       ·   --ignore-whitespace
541
542       ·   -C
543
544       are incompatible with the following options:
545
546       ·   --merge
547
548       ·   --strategy
549
550       ·   --strategy-option
551
552       ·   --allow-empty-message
553
554       ·   --[no-]autosquash
555
556       ·   --rebase-merges
557
558       ·   --preserve-merges
559
560       ·   --interactive
561
562       ·   --exec
563
564       ·   --keep-empty
565
566       ·   --edit-todo
567
568       ·   --root when used in combination with --onto
569
570       In addition, the following pairs of options are incompatible:
571
572       ·   --preserve-merges and --interactive
573
574       ·   --preserve-merges and --signoff
575
576       ·   --preserve-merges and --rebase-merges
577
578       ·   --rebase-merges and --strategy
579
580       ·   --rebase-merges and --strategy-option
581

BEHAVIORAL DIFFERENCES

583       There are some subtle differences how the backends behave.
584
585   Empty commits
586       The am backend drops any "empty" commits, regardless of whether the
587       commit started empty (had no changes relative to its parent to start
588       with) or ended empty (all changes were already applied upstream in
589       other commits).
590
591       The interactive backend drops commits by default that started empty and
592       halts if it hits a commit that ended up empty. The --keep-empty option
593       exists for the interactive backend to allow it to keep commits that
594       started empty.
595
596   Directory rename detection
597       Directory rename heuristics are enabled in the merge and interactive
598       backends. Due to the lack of accurate tree information, directory
599       rename detection is disabled in the am backend.
600

MERGE STRATEGIES

602       The merge mechanism (git merge and git pull commands) allows the
603       backend merge strategies to be chosen with -s option. Some strategies
604       can also take their own options, which can be passed by giving
605       -X<option> arguments to git merge and/or git pull.
606
607       resolve
608           This can only resolve two heads (i.e. the current branch and
609           another branch you pulled from) using a 3-way merge algorithm. It
610           tries to carefully detect criss-cross merge ambiguities and is
611           considered generally safe and fast.
612
613       recursive
614           This can only resolve two heads using a 3-way merge algorithm. When
615           there is more than one common ancestor that can be used for 3-way
616           merge, it creates a merged tree of the common ancestors and uses
617           that as the reference tree for the 3-way merge. This has been
618           reported to result in fewer merge conflicts without causing
619           mismerges by tests done on actual merge commits taken from Linux
620           2.6 kernel development history. Additionally this can detect and
621           handle merges involving renames, but currently cannot make use of
622           detected copies. This is the default merge strategy when pulling or
623           merging one branch.
624
625           The recursive strategy can take the following options:
626
627           ours
628               This option forces conflicting hunks to be auto-resolved
629               cleanly by favoring our version. Changes from the other tree
630               that do not conflict with our side are reflected to the merge
631               result. For a binary file, the entire contents are taken from
632               our side.
633
634               This should not be confused with the ours merge strategy, which
635               does not even look at what the other tree contains at all. It
636               discards everything the other tree did, declaring our history
637               contains all that happened in it.
638
639           theirs
640               This is the opposite of ours; note that, unlike ours, there is
641               no theirs merge strategy to confuse this merge option with.
642
643           patience
644               With this option, merge-recursive spends a little extra time to
645               avoid mismerges that sometimes occur due to unimportant
646               matching lines (e.g., braces from distinct functions). Use this
647               when the branches to be merged have diverged wildly. See also
648               git-diff(1) --patience.
649
650           diff-algorithm=[patience|minimal|histogram|myers]
651               Tells merge-recursive to use a different diff algorithm, which
652               can help avoid mismerges that occur due to unimportant matching
653               lines (such as braces from distinct functions). See also git-
654               diff(1) --diff-algorithm.
655
656           ignore-space-change, ignore-all-space, ignore-space-at-eol,
657           ignore-cr-at-eol
658               Treats lines with the indicated type of whitespace change as
659               unchanged for the sake of a three-way merge. Whitespace changes
660               mixed with other changes to a line are not ignored. See also
661               git-diff(1) -b, -w, --ignore-space-at-eol, and
662               --ignore-cr-at-eol.
663
664               ·   If their version only introduces whitespace changes to a
665                   line, our version is used;
666
667               ·   If our version introduces whitespace changes but their
668                   version includes a substantial change, their version is
669                   used;
670
671               ·   Otherwise, the merge proceeds in the usual way.
672
673           renormalize
674               This runs a virtual check-out and check-in of all three stages
675               of a file when resolving a three-way merge. This option is
676               meant to be used when merging branches with different clean
677               filters or end-of-line normalization rules. See "Merging
678               branches with differing checkin/checkout attributes" in
679               gitattributes(5) for details.
680
681           no-renormalize
682               Disables the renormalize option. This overrides the
683               merge.renormalize configuration variable.
684
685           no-renames
686               Turn off rename detection. This overrides the merge.renames
687               configuration variable. See also git-diff(1) --no-renames.
688
689           find-renames[=<n>]
690               Turn on rename detection, optionally setting the similarity
691               threshold. This is the default. This overrides the
692               merge.renames configuration variable. See also git-diff(1)
693               --find-renames.
694
695           rename-threshold=<n>
696               Deprecated synonym for find-renames=<n>.
697
698           subtree[=<path>]
699               This option is a more advanced form of subtree strategy, where
700               the strategy makes a guess on how two trees must be shifted to
701               match with each other when merging. Instead, the specified path
702               is prefixed (or stripped from the beginning) to make the shape
703               of two trees to match.
704
705       octopus
706           This resolves cases with more than two heads, but refuses to do a
707           complex merge that needs manual resolution. It is primarily meant
708           to be used for bundling topic branch heads together. This is the
709           default merge strategy when pulling or merging more than one
710           branch.
711
712       ours
713           This resolves any number of heads, but the resulting tree of the
714           merge is always that of the current branch head, effectively
715           ignoring all changes from all other branches. It is meant to be
716           used to supersede old development history of side branches. Note
717           that this is different from the -Xours option to the recursive
718           merge strategy.
719
720       subtree
721           This is a modified recursive strategy. When merging trees A and B,
722           if B corresponds to a subtree of A, B is first adjusted to match
723           the tree structure of A, instead of reading the trees at the same
724           level. This adjustment is also done to the common ancestor tree.
725
726       With the strategies that use 3-way merge (including the default,
727       recursive), if a change is made on both branches, but later reverted on
728       one of the branches, that change will be present in the merged result;
729       some people find this behavior confusing. It occurs because only the
730       heads and the merge base are considered when performing a merge, not
731       the individual commits. The merge algorithm therefore considers the
732       reverted change as no change at all, and substitutes the changed
733       version instead.
734

NOTES

736       You should understand the implications of using git rebase on a
737       repository that you share. See also RECOVERING FROM UPSTREAM REBASE
738       below.
739
740       When the git-rebase command is run, it will first execute a
741       "pre-rebase" hook if one exists. You can use this hook to do sanity
742       checks and reject the rebase if it isn’t appropriate. Please see the
743       template pre-rebase hook script for an example.
744
745       Upon completion, <branch> will be the current branch.
746

INTERACTIVE MODE

748       Rebasing interactively means that you have a chance to edit the commits
749       which are rebased. You can reorder the commits, and you can remove them
750       (weeding out bad or otherwise unwanted patches).
751
752       The interactive mode is meant for this type of workflow:
753
754        1. have a wonderful idea
755
756        2. hack on the code
757
758        3. prepare a series for submission
759
760        4. submit
761
762       where point 2. consists of several instances of
763
764       a) regular use
765
766        1. finish something worthy of a commit
767
768        2. commit
769
770       b) independent fixup
771
772        1. realize that something does not work
773
774        2. fix that
775
776        3. commit it
777
778       Sometimes the thing fixed in b.2. cannot be amended to the not-quite
779       perfect commit it fixes, because that commit is buried deeply in a
780       patch series. That is exactly what interactive rebase is for: use it
781       after plenty of "a"s and "b"s, by rearranging and editing commits, and
782       squashing multiple commits into one.
783
784       Start it with the last commit you want to retain as-is:
785
786           git rebase -i <after-this-commit>
787
788       An editor will be fired up with all the commits in your current branch
789       (ignoring merge commits), which come after the given commit. You can
790       reorder the commits in this list to your heart’s content, and you can
791       remove them. The list looks more or less like this:
792
793           pick deadbee The oneline of this commit
794           pick fa1afe1 The oneline of the next commit
795           ...
796
797
798       The oneline descriptions are purely for your pleasure; git rebase will
799       not look at them but at the commit names ("deadbee" and "fa1afe1" in
800       this example), so do not delete or edit the names.
801
802       By replacing the command "pick" with the command "edit", you can tell
803       git rebase to stop after applying that commit, so that you can edit the
804       files and/or the commit message, amend the commit, and continue
805       rebasing.
806
807       To interrupt the rebase (just like an "edit" command would do, but
808       without cherry-picking any commit first), use the "break" command.
809
810       If you just want to edit the commit message for a commit, replace the
811       command "pick" with the command "reword".
812
813       To drop a commit, replace the command "pick" with "drop", or just
814       delete the matching line.
815
816       If you want to fold two or more commits into one, replace the command
817       "pick" for the second and subsequent commits with "squash" or "fixup".
818       If the commits had different authors, the folded commit will be
819       attributed to the author of the first commit. The suggested commit
820       message for the folded commit is the concatenation of the commit
821       messages of the first commit and of those with the "squash" command,
822       but omits the commit messages of commits with the "fixup" command.
823
824       git rebase will stop when "pick" has been replaced with "edit" or when
825       a command fails due to merge errors. When you are done editing and/or
826       resolving conflicts you can continue with git rebase --continue.
827
828       For example, if you want to reorder the last 5 commits, such that what
829       was HEAD~4 becomes the new HEAD. To achieve that, you would call git
830       rebase like this:
831
832           $ git rebase -i HEAD~5
833
834
835       And move the first patch to the end of the list.
836
837       You might want to preserve merges, if you have a history like this:
838
839                      X
840                       \
841                    A---M---B
842                   /
843           ---o---O---P---Q
844
845
846       Suppose you want to rebase the side branch starting at "A" to "Q". Make
847       sure that the current HEAD is "B", and call
848
849           $ git rebase -i -p --onto Q O
850
851
852       Reordering and editing commits usually creates untested intermediate
853       steps. You may want to check that your history editing did not break
854       anything by running a test, or at least recompiling at intermediate
855       points in history by using the "exec" command (shortcut "x"). You may
856       do so by creating a todo list like this one:
857
858           pick deadbee Implement feature XXX
859           fixup f1a5c00 Fix to feature XXX
860           exec make
861           pick c0ffeee The oneline of the next commit
862           edit deadbab The oneline of the commit after
863           exec cd subdir; make test
864           ...
865
866
867       The interactive rebase will stop when a command fails (i.e. exits with
868       non-0 status) to give you an opportunity to fix the problem. You can
869       continue with git rebase --continue.
870
871       The "exec" command launches the command in a shell (the one specified
872       in $SHELL, or the default shell if $SHELL is not set), so you can use
873       shell features (like "cd", ">", ";" ...). The command is run from the
874       root of the working tree.
875
876           $ git rebase -i --exec "make test"
877
878
879       This command lets you check that intermediate commits are compilable.
880       The todo list becomes like that:
881
882           pick 5928aea one
883           exec make test
884           pick 04d0fda two
885           exec make test
886           pick ba46169 three
887           exec make test
888           pick f4593f9 four
889           exec make test
890
891

SPLITTING COMMITS

893       In interactive mode, you can mark commits with the action "edit".
894       However, this does not necessarily mean that git rebase expects the
895       result of this edit to be exactly one commit. Indeed, you can undo the
896       commit, or you can add other commits. This can be used to split a
897       commit into two:
898
899       ·   Start an interactive rebase with git rebase -i <commit>^, where
900           <commit> is the commit you want to split. In fact, any commit range
901           will do, as long as it contains that commit.
902
903       ·   Mark the commit you want to split with the action "edit".
904
905       ·   When it comes to editing that commit, execute git reset HEAD^. The
906           effect is that the HEAD is rewound by one, and the index follows
907           suit. However, the working tree stays the same.
908
909       ·   Now add the changes to the index that you want to have in the first
910           commit. You can use git add (possibly interactively) or git gui (or
911           both) to do that.
912
913       ·   Commit the now-current index with whatever commit message is
914           appropriate now.
915
916       ·   Repeat the last two steps until your working tree is clean.
917
918       ·   Continue the rebase with git rebase --continue.
919
920       If you are not absolutely sure that the intermediate revisions are
921       consistent (they compile, pass the testsuite, etc.) you should use git
922       stash to stash away the not-yet-committed changes after each commit,
923       test, and amend the commit if fixes are necessary.
924

RECOVERING FROM UPSTREAM REBASE

926       Rebasing (or any other form of rewriting) a branch that others have
927       based work on is a bad idea: anyone downstream of it is forced to
928       manually fix their history. This section explains how to do the fix
929       from the downstream’s point of view. The real fix, however, would be to
930       avoid rebasing the upstream in the first place.
931
932       To illustrate, suppose you are in a situation where someone develops a
933       subsystem branch, and you are working on a topic that is dependent on
934       this subsystem. You might end up with a history like the following:
935
936               o---o---o---o---o---o---o---o  master
937                    \
938                     o---o---o---o---o  subsystem
939                                      \
940                                       *---*---*  topic
941
942
943       If subsystem is rebased against master, the following happens:
944
945               o---o---o---o---o---o---o---o  master
946                    \                       \
947                     o---o---o---o---o       o'--o'--o'--o'--o'  subsystem
948                                      \
949                                       *---*---*  topic
950
951
952       If you now continue development as usual, and eventually merge topic to
953       subsystem, the commits from subsystem will remain duplicated forever:
954
955               o---o---o---o---o---o---o---o  master
956                    \                       \
957                     o---o---o---o---o       o'--o'--o'--o'--o'--M  subsystem
958                                      \                         /
959                                       *---*---*-..........-*--*  topic
960
961
962       Such duplicates are generally frowned upon because they clutter up
963       history, making it harder to follow. To clean things up, you need to
964       transplant the commits on topic to the new subsystem tip, i.e., rebase
965       topic. This becomes a ripple effect: anyone downstream from topic is
966       forced to rebase too, and so on!
967
968       There are two kinds of fixes, discussed in the following subsections:
969
970       Easy case: The changes are literally the same.
971           This happens if the subsystem rebase was a simple rebase and had no
972           conflicts.
973
974       Hard case: The changes are not the same.
975           This happens if the subsystem rebase had conflicts, or used
976           --interactive to omit, edit, squash, or fixup commits; or if the
977           upstream used one of commit --amend, reset, or filter-branch.
978
979   The easy case
980       Only works if the changes (patch IDs based on the diff contents) on
981       subsystem are literally the same before and after the rebase subsystem
982       did.
983
984       In that case, the fix is easy because git rebase knows to skip changes
985       that are already present in the new upstream. So if you say (assuming
986       you’re on topic)
987
988               $ git rebase subsystem
989
990
991       you will end up with the fixed history
992
993               o---o---o---o---o---o---o---o  master
994                                            \
995                                             o'--o'--o'--o'--o'  subsystem
996                                                              \
997                                                               *---*---*  topic
998
999
1000   The hard case
1001       Things get more complicated if the subsystem changes do not exactly
1002       correspond to the ones before the rebase.
1003
1004           Note
1005           While an "easy case recovery" sometimes appears to be successful
1006           even in the hard case, it may have unintended consequences. For
1007           example, a commit that was removed via git rebase --interactive
1008           will be resurrected!
1009
1010       The idea is to manually tell git rebase "where the old subsystem ended
1011       and your topic began", that is, what the old merge-base between them
1012       was. You will have to find a way to name the last commit of the old
1013       subsystem, for example:
1014
1015       ·   With the subsystem reflog: after git fetch, the old tip of
1016           subsystem is at subsystem@{1}. Subsequent fetches will increase the
1017           number. (See git-reflog(1).)
1018
1019       ·   Relative to the tip of topic: knowing that your topic has three
1020           commits, the old tip of subsystem must be topic~3.
1021
1022       You can then transplant the old subsystem..topic to the new tip by
1023       saying (for the reflog case, and assuming you are on topic already):
1024
1025               $ git rebase --onto subsystem subsystem@{1}
1026
1027
1028       The ripple effect of a "hard case" recovery is especially bad: everyone
1029       downstream from topic will now have to perform a "hard case" recovery
1030       too!
1031

REBASING MERGES

1033       The interactive rebase command was originally designed to handle
1034       individual patch series. As such, it makes sense to exclude merge
1035       commits from the todo list, as the developer may have merged the
1036       then-current master while working on the branch, only to rebase all the
1037       commits onto master eventually (skipping the merge commits).
1038
1039       However, there are legitimate reasons why a developer may want to
1040       recreate merge commits: to keep the branch structure (or "commit
1041       topology") when working on multiple, inter-related branches.
1042
1043       In the following example, the developer works on a topic branch that
1044       refactors the way buttons are defined, and on another topic branch that
1045       uses that refactoring to implement a "Report a bug" button. The output
1046       of git log --graph --format=%s -5 may look like this:
1047
1048           *   Merge branch 'report-a-bug'
1049           |\
1050           | * Add the feedback button
1051           * | Merge branch 'refactor-button'
1052           |\ \
1053           | |/
1054           | * Use the Button class for all buttons
1055           | * Extract a generic Button class from the DownloadButton one
1056
1057
1058       The developer might want to rebase those commits to a newer master
1059       while keeping the branch topology, for example when the first topic
1060       branch is expected to be integrated into master much earlier than the
1061       second one, say, to resolve merge conflicts with changes to the
1062       DownloadButton class that made it into master.
1063
1064       This rebase can be performed using the --rebase-merges option. It will
1065       generate a todo list looking like this:
1066
1067           label onto
1068
1069           # Branch: refactor-button
1070           reset onto
1071           pick 123456 Extract a generic Button class from the DownloadButton one
1072           pick 654321 Use the Button class for all buttons
1073           label refactor-button
1074
1075           # Branch: report-a-bug
1076           reset refactor-button # Use the Button class for all buttons
1077           pick abcdef Add the feedback button
1078           label report-a-bug
1079
1080           reset onto
1081           merge -C a1b2c3 refactor-button # Merge 'refactor-button'
1082           merge -C 6f5e4d report-a-bug # Merge 'report-a-bug'
1083
1084
1085       In contrast to a regular interactive rebase, there are label, reset and
1086       merge commands in addition to pick ones.
1087
1088       The label command associates a label with the current HEAD when that
1089       command is executed. These labels are created as worktree-local refs
1090       (refs/rewritten/<label>) that will be deleted when the rebase finishes.
1091       That way, rebase operations in multiple worktrees linked to the same
1092       repository do not interfere with one another. If the label command
1093       fails, it is rescheduled immediately, with a helpful message how to
1094       proceed.
1095
1096       The reset command resets the HEAD, index and worktree to the specified
1097       revision. It is similar to an exec git reset --hard <label>, but
1098       refuses to overwrite untracked files. If the reset command fails, it is
1099       rescheduled immediately, with a helpful message how to edit the todo
1100       list (this typically happens when a reset command was inserted into the
1101       todo list manually and contains a typo).
1102
1103       The merge command will merge the specified revision(s) into whatever is
1104       HEAD at that time. With -C <original-commit>, the commit message of the
1105       specified merge commit will be used. When the -C is changed to a
1106       lower-case -c, the message will be opened in an editor after a
1107       successful merge so that the user can edit the message.
1108
1109       If a merge command fails for any reason other than merge conflicts
1110       (i.e. when the merge operation did not even start), it is rescheduled
1111       immediately.
1112
1113       At this time, the merge command will always use the recursive merge
1114       strategy for regular merges, and octopus for octopus merges, with no
1115       way to choose a different one. To work around this, an exec command can
1116       be used to call git merge explicitly, using the fact that the labels
1117       are worktree-local refs (the ref refs/rewritten/onto would correspond
1118       to the label onto, for example).
1119
1120       Note: the first command (label onto) labels the revision onto which the
1121       commits are rebased; The name onto is just a convention, as a nod to
1122       the --onto option.
1123
1124       It is also possible to introduce completely new merge commits from
1125       scratch by adding a command of the form merge <merge-head>. This form
1126       will generate a tentative commit message and always open an editor to
1127       let the user edit it. This can be useful e.g. when a topic branch turns
1128       out to address more than a single concern and wants to be split into
1129       two or even more topic branches. Consider this todo list:
1130
1131           pick 192837 Switch from GNU Makefiles to CMake
1132           pick 5a6c7e Document the switch to CMake
1133           pick 918273 Fix detection of OpenSSL in CMake
1134           pick afbecd http: add support for TLS v1.3
1135           pick fdbaec Fix detection of cURL in CMake on Windows
1136
1137
1138       The one commit in this list that is not related to CMake may very well
1139       have been motivated by working on fixing all those bugs introduced by
1140       switching to CMake, but it addresses a different concern. To split this
1141       branch into two topic branches, the todo list could be edited like
1142       this:
1143
1144           label onto
1145
1146           pick afbecd http: add support for TLS v1.3
1147           label tlsv1.3
1148
1149           reset onto
1150           pick 192837 Switch from GNU Makefiles to CMake
1151           pick 918273 Fix detection of OpenSSL in CMake
1152           pick fdbaec Fix detection of cURL in CMake on Windows
1153           pick 5a6c7e Document the switch to CMake
1154           label cmake
1155
1156           reset onto
1157           merge tlsv1.3
1158           merge cmake
1159
1160

BUGS

1162       The todo list presented by --preserve-merges --interactive does not
1163       represent the topology of the revision graph. Editing commits and
1164       rewording their commit messages should work fine, but attempts to
1165       reorder commits tend to produce counterintuitive results. Use
1166       --rebase-merges in such scenarios instead.
1167
1168       For example, an attempt to rearrange
1169
1170           1 --- 2 --- 3 --- 4 --- 5
1171
1172
1173       to
1174
1175           1 --- 2 --- 4 --- 3 --- 5
1176
1177
1178       by moving the "pick 4" line will result in the following history:
1179
1180                   3
1181                  /
1182           1 --- 2 --- 4 --- 5
1183
1184

GIT

1186       Part of the git(1) suite
1187

NOTES

1189        1. revert-a-faulty-merge How-To
1190           file:///usr/share/doc/git/howto/revert-a-faulty-merge.html
1191
1192
1193
1194Git 2.21.0                        02/24/2019                     GIT-REBASE(1)
Impressum