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>]
10               [--onto <newbase> | --keep-base] [<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

DESCRIPTION

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

CONFIGURATION

174       rebase.useBuiltin
175           Unused configuration variable. Used in Git versions 2.20 and 2.21
176           as an escape hatch to enable the legacy shellscript implementation
177           of rebase. Now the built-in rewrite of it in C is always used.
178           Setting this will emit a warning, to alert any remaining users that
179           setting this now does nothing.
180
181       rebase.backend
182           Default backend to use for rebasing. Possible choices are apply or
183           merge. In the future, if the merge backend gains all remaining
184           capabilities of the apply backend, this setting may become unused.
185
186       rebase.stat
187           Whether to show a diffstat of what changed upstream since the last
188           rebase. False by default.
189
190       rebase.autoSquash
191           If set to true enable --autosquash option by default.
192
193       rebase.autoStash
194           When set to true, automatically create a temporary stash entry
195           before the operation begins, and apply it after the operation ends.
196           This means that you can run rebase on a dirty worktree. However,
197           use with care: the final stash application after a successful
198           rebase might result in non-trivial conflicts. This option can be
199           overridden by the --no-autostash and --autostash options of git-
200           rebase(1). Defaults to false.
201
202       rebase.missingCommitsCheck
203           If set to "warn", git rebase -i will print a warning if some
204           commits are removed (e.g. a line was deleted), however the rebase
205           will still proceed. If set to "error", it will print the previous
206           warning and stop the rebase, git rebase --edit-todo can then be
207           used to correct the error. If set to "ignore", no checking is done.
208           To drop a commit without warning or error, use the drop command in
209           the todo list. Defaults to "ignore".
210
211       rebase.instructionFormat
212           A format string, as specified in git-log(1), to be used for the
213           todo list during an interactive rebase. The format will
214           automatically have the long commit hash prepended to the format.
215
216       rebase.abbreviateCommands
217           If set to true, git rebase will use abbreviated command names in
218           the todo list resulting in something like this:
219
220                       p deadbee The oneline of the commit
221                       p fa1afe1 The oneline of the next commit
222                       ...
223
224           instead of:
225
226                       pick deadbee The oneline of the commit
227                       pick fa1afe1 The oneline of the next commit
228                       ...
229
230           Defaults to false.
231
232       rebase.rescheduleFailedExec
233           Automatically reschedule exec commands that failed. This only makes
234           sense in interactive mode (or when an --exec option was provided).
235           This is the same as specifying the --reschedule-failed-exec option.
236

OPTIONS

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

INCOMPATIBLE OPTIONS

575       The following options:
576
577       ·   --apply
578
579       ·   --committer-date-is-author-date
580
581       ·   --ignore-date
582
583       ·   --ignore-whitespace
584
585       ·   --whitespace
586
587       ·   -C
588
589       are incompatible with the following options:
590
591       ·   --merge
592
593       ·   --strategy
594
595       ·   --strategy-option
596
597       ·   --allow-empty-message
598
599       ·   --[no-]autosquash
600
601       ·   --rebase-merges
602
603       ·   --preserve-merges
604
605       ·   --interactive
606
607       ·   --exec
608
609       ·   --keep-empty
610
611       ·   --empty=
612
613       ·   --edit-todo
614
615       ·   --root when used in combination with --onto
616
617       In addition, the following pairs of options are incompatible:
618
619       ·   --preserve-merges and --interactive
620
621       ·   --preserve-merges and --signoff
622
623       ·   --preserve-merges and --rebase-merges
624
625       ·   --preserve-merges and --empty=
626
627       ·   --keep-base and --onto
628
629       ·   --keep-base and --root
630

BEHAVIORAL DIFFERENCES

632       git rebase has two primary backends: apply and merge. (The apply
633       backend used to known as the am backend, but the name led to confusion
634       as it looks like a verb instead of a noun. Also, the merge backend used
635       to be known as the interactive backend, but it is now used for
636       non-interactive cases as well. Both were renamed based on lower-level
637       functionality that underpinned each.) There are some subtle differences
638       in how these two backends behave:
639
640   Empty commits
641       The apply backend unfortunately drops intentionally empty commits, i.e.
642       commits that started empty, though these are rare in practice. It also
643       drops commits that become empty and has no option for controlling this
644       behavior.
645
646       The merge backend keeps intentionally empty commits. Similar to the
647       apply backend, by default the merge backend drops commits that become
648       empty unless -i/--interactive is specified (in which case it stops and
649       asks the user what to do). The merge backend also has an
650       --empty={drop,keep,ask} option for changing the behavior of handling
651       commits that become empty.
652
653   Directory rename detection
654       Due to the lack of accurate tree information (arising from constructing
655       fake ancestors with the limited information available in patches),
656       directory rename detection is disabled in the apply backend. Disabled
657       directory rename detection means that if one side of history renames a
658       directory and the other adds new files to the old directory, then the
659       new files will be left behind in the old directory without any warning
660       at the time of rebasing that you may want to move these files into the
661       new directory.
662
663       Directory rename detection works with the merge backend to provide you
664       warnings in such cases.
665
666   Context
667       The apply backend works by creating a sequence of patches (by calling
668       format-patch internally), and then applying the patches in sequence
669       (calling am internally). Patches are composed of multiple hunks, each
670       with line numbers, a context region, and the actual changes. The line
671       numbers have to be taken with some fuzz, since the other side will
672       likely have inserted or deleted lines earlier in the file. The context
673       region is meant to help find how to adjust the line numbers in order to
674       apply the changes to the right lines. However, if multiple areas of the
675       code have the same surrounding lines of context, the wrong one can be
676       picked. There are real-world cases where this has caused commits to be
677       reapplied incorrectly with no conflicts reported. Setting diff.context
678       to a larger value may prevent such types of problems, but increases the
679       chance of spurious conflicts (since it will require more lines of
680       matching context to apply).
681
682       The merge backend works with a full copy of each relevant file,
683       insulating it from these types of problems.
684
685   Labelling of conflicts markers
686       When there are content conflicts, the merge machinery tries to annotate
687       each side’s conflict markers with the commits where the content came
688       from. Since the apply backend drops the original information about the
689       rebased commits and their parents (and instead generates new fake
690       commits based off limited information in the generated patches), those
691       commits cannot be identified; instead it has to fall back to a commit
692       summary. Also, when merge.conflictStyle is set to diff3, the apply
693       backend will use "constructed merge base" to label the content from the
694       merge base, and thus provide no information about the merge base commit
695       whatsoever.
696
697       The merge backend works with the full commits on both sides of history
698       and thus has no such limitations.
699
700   Hooks
701       The apply backend has not traditionally called the post-commit hook,
702       while the merge backend has. However, this was by accident of
703       implementation rather than by design. Both backends should have the
704       same behavior, though it is not clear which one is correct.
705
706   Interruptability
707       The apply backend has safety problems with an ill-timed interrupt; if
708       the user presses Ctrl-C at the wrong time to try to abort the rebase,
709       the rebase can enter a state where it cannot be aborted with a
710       subsequent git rebase --abort. The merge backend does not appear to
711       suffer from the same shortcoming. (See
712       https://lore.kernel.org/git/20200207132152.GC2868@szeder.dev/ for
713       details.)
714
715   Commit Rewording
716       When a conflict occurs while rebasing, rebase stops and asks the user
717       to resolve. Since the user may need to make notable changes while
718       resolving conflicts, after conflicts are resolved and the user has run
719       git rebase --continue, the rebase should open an editor and ask the
720       user to update the commit message. The merge backend does this, while
721       the apply backend blindly applies the original commit message.
722
723   Miscellaneous differences
724       There are a few more behavioral differences that most folks would
725       probably consider inconsequential but which are mentioned for
726       completeness:
727
728       ·   Reflog: The two backends will use different wording when describing
729           the changes made in the reflog, though both will make use of the
730           word "rebase".
731
732       ·   Progress, informational, and error messages: The two backends
733           provide slightly different progress and informational messages.
734           Also, the apply backend writes error messages (such as "Your files
735           would be overwritten...") to stdout, while the merge backend writes
736           them to stderr.
737
738       ·   State directories: The two backends keep their state in different
739           directories under .git/
740

MERGE STRATEGIES

742       The merge mechanism (git merge and git pull commands) allows the
743       backend merge strategies to be chosen with -s option. Some strategies
744       can also take their own options, which can be passed by giving
745       -X<option> arguments to git merge and/or git pull.
746
747       resolve
748           This can only resolve two heads (i.e. the current branch and
749           another branch you pulled from) using a 3-way merge algorithm. It
750           tries to carefully detect criss-cross merge ambiguities and is
751           considered generally safe and fast.
752
753       recursive
754           This can only resolve two heads using a 3-way merge algorithm. When
755           there is more than one common ancestor that can be used for 3-way
756           merge, it creates a merged tree of the common ancestors and uses
757           that as the reference tree for the 3-way merge. This has been
758           reported to result in fewer merge conflicts without causing
759           mismerges by tests done on actual merge commits taken from Linux
760           2.6 kernel development history. Additionally this can detect and
761           handle merges involving renames, but currently cannot make use of
762           detected copies. This is the default merge strategy when pulling or
763           merging one branch.
764
765           The recursive strategy can take the following options:
766
767           ours
768               This option forces conflicting hunks to be auto-resolved
769               cleanly by favoring our version. Changes from the other tree
770               that do not conflict with our side are reflected in the merge
771               result. For a binary file, the entire contents are taken from
772               our side.
773
774               This should not be confused with the ours merge strategy, which
775               does not even look at what the other tree contains at all. It
776               discards everything the other tree did, declaring our history
777               contains all that happened in it.
778
779           theirs
780               This is the opposite of ours; note that, unlike ours, there is
781               no theirs merge strategy to confuse this merge option with.
782
783           patience
784               With this option, merge-recursive spends a little extra time to
785               avoid mismerges that sometimes occur due to unimportant
786               matching lines (e.g., braces from distinct functions). Use this
787               when the branches to be merged have diverged wildly. See also
788               git-diff(1) --patience.
789
790           diff-algorithm=[patience|minimal|histogram|myers]
791               Tells merge-recursive to use a different diff algorithm, which
792               can help avoid mismerges that occur due to unimportant matching
793               lines (such as braces from distinct functions). See also git-
794               diff(1) --diff-algorithm.
795
796           ignore-space-change, ignore-all-space, ignore-space-at-eol,
797           ignore-cr-at-eol
798               Treats lines with the indicated type of whitespace change as
799               unchanged for the sake of a three-way merge. Whitespace changes
800               mixed with other changes to a line are not ignored. See also
801               git-diff(1) -b, -w, --ignore-space-at-eol, and
802               --ignore-cr-at-eol.
803
804               ·   If their version only introduces whitespace changes to a
805                   line, our version is used;
806
807               ·   If our version introduces whitespace changes but their
808                   version includes a substantial change, their version is
809                   used;
810
811               ·   Otherwise, the merge proceeds in the usual way.
812
813           renormalize
814               This runs a virtual check-out and check-in of all three stages
815               of a file when resolving a three-way merge. This option is
816               meant to be used when merging branches with different clean
817               filters or end-of-line normalization rules. See "Merging
818               branches with differing checkin/checkout attributes" in
819               gitattributes(5) for details.
820
821           no-renormalize
822               Disables the renormalize option. This overrides the
823               merge.renormalize configuration variable.
824
825           no-renames
826               Turn off rename detection. This overrides the merge.renames
827               configuration variable. See also git-diff(1) --no-renames.
828
829           find-renames[=<n>]
830               Turn on rename detection, optionally setting the similarity
831               threshold. This is the default. This overrides the
832               merge.renames configuration variable. See also git-diff(1)
833               --find-renames.
834
835           rename-threshold=<n>
836               Deprecated synonym for find-renames=<n>.
837
838           subtree[=<path>]
839               This option is a more advanced form of subtree strategy, where
840               the strategy makes a guess on how two trees must be shifted to
841               match with each other when merging. Instead, the specified path
842               is prefixed (or stripped from the beginning) to make the shape
843               of two trees to match.
844
845       octopus
846           This resolves cases with more than two heads, but refuses to do a
847           complex merge that needs manual resolution. It is primarily meant
848           to be used for bundling topic branch heads together. This is the
849           default merge strategy when pulling or merging more than one
850           branch.
851
852       ours
853           This resolves any number of heads, but the resulting tree of the
854           merge is always that of the current branch head, effectively
855           ignoring all changes from all other branches. It is meant to be
856           used to supersede old development history of side branches. Note
857           that this is different from the -Xours option to the recursive
858           merge strategy.
859
860       subtree
861           This is a modified recursive strategy. When merging trees A and B,
862           if B corresponds to a subtree of A, B is first adjusted to match
863           the tree structure of A, instead of reading the trees at the same
864           level. This adjustment is also done to the common ancestor tree.
865
866       With the strategies that use 3-way merge (including the default,
867       recursive), if a change is made on both branches, but later reverted on
868       one of the branches, that change will be present in the merged result;
869       some people find this behavior confusing. It occurs because only the
870       heads and the merge base are considered when performing a merge, not
871       the individual commits. The merge algorithm therefore considers the
872       reverted change as no change at all, and substitutes the changed
873       version instead.
874

NOTES

876       You should understand the implications of using git rebase on a
877       repository that you share. See also RECOVERING FROM UPSTREAM REBASE
878       below.
879
880       When the git-rebase command is run, it will first execute a
881       "pre-rebase" hook if one exists. You can use this hook to do sanity
882       checks and reject the rebase if it isn’t appropriate. Please see the
883       template pre-rebase hook script for an example.
884
885       Upon completion, <branch> will be the current branch.
886

INTERACTIVE MODE

888       Rebasing interactively means that you have a chance to edit the commits
889       which are rebased. You can reorder the commits, and you can remove them
890       (weeding out bad or otherwise unwanted patches).
891
892       The interactive mode is meant for this type of workflow:
893
894        1. have a wonderful idea
895
896        2. hack on the code
897
898        3. prepare a series for submission
899
900        4. submit
901
902       where point 2. consists of several instances of
903
904       a) regular use
905
906        1. finish something worthy of a commit
907
908        2. commit
909
910       b) independent fixup
911
912        1. realize that something does not work
913
914        2. fix that
915
916        3. commit it
917
918       Sometimes the thing fixed in b.2. cannot be amended to the not-quite
919       perfect commit it fixes, because that commit is buried deeply in a
920       patch series. That is exactly what interactive rebase is for: use it
921       after plenty of "a"s and "b"s, by rearranging and editing commits, and
922       squashing multiple commits into one.
923
924       Start it with the last commit you want to retain as-is:
925
926           git rebase -i <after-this-commit>
927
928       An editor will be fired up with all the commits in your current branch
929       (ignoring merge commits), which come after the given commit. You can
930       reorder the commits in this list to your heart’s content, and you can
931       remove them. The list looks more or less like this:
932
933           pick deadbee The oneline of this commit
934           pick fa1afe1 The oneline of the next commit
935           ...
936
937       The oneline descriptions are purely for your pleasure; git rebase will
938       not look at them but at the commit names ("deadbee" and "fa1afe1" in
939       this example), so do not delete or edit the names.
940
941       By replacing the command "pick" with the command "edit", you can tell
942       git rebase to stop after applying that commit, so that you can edit the
943       files and/or the commit message, amend the commit, and continue
944       rebasing.
945
946       To interrupt the rebase (just like an "edit" command would do, but
947       without cherry-picking any commit first), use the "break" command.
948
949       If you just want to edit the commit message for a commit, replace the
950       command "pick" with the command "reword".
951
952       To drop a commit, replace the command "pick" with "drop", or just
953       delete the matching line.
954
955       If you want to fold two or more commits into one, replace the command
956       "pick" for the second and subsequent commits with "squash" or "fixup".
957       If the commits had different authors, the folded commit will be
958       attributed to the author of the first commit. The suggested commit
959       message for the folded commit is the concatenation of the commit
960       messages of the first commit and of those with the "squash" command,
961       but omits the commit messages of commits with the "fixup" command.
962
963       git rebase will stop when "pick" has been replaced with "edit" or when
964       a command fails due to merge errors. When you are done editing and/or
965       resolving conflicts you can continue with git rebase --continue.
966
967       For example, if you want to reorder the last 5 commits, such that what
968       was HEAD~4 becomes the new HEAD. To achieve that, you would call git
969       rebase like this:
970
971           $ git rebase -i HEAD~5
972
973       And move the first patch to the end of the list.
974
975       You might want to recreate merge commits, e.g. if you have a history
976       like this:
977
978                      X
979                       \
980                    A---M---B
981                   /
982           ---o---O---P---Q
983
984       Suppose you want to rebase the side branch starting at "A" to "Q". Make
985       sure that the current HEAD is "B", and call
986
987           $ git rebase -i -r --onto Q O
988
989       Reordering and editing commits usually creates untested intermediate
990       steps. You may want to check that your history editing did not break
991       anything by running a test, or at least recompiling at intermediate
992       points in history by using the "exec" command (shortcut "x"). You may
993       do so by creating a todo list like this one:
994
995           pick deadbee Implement feature XXX
996           fixup f1a5c00 Fix to feature XXX
997           exec make
998           pick c0ffeee The oneline of the next commit
999           edit deadbab The oneline of the commit after
1000           exec cd subdir; make test
1001           ...
1002
1003       The interactive rebase will stop when a command fails (i.e. exits with
1004       non-0 status) to give you an opportunity to fix the problem. You can
1005       continue with git rebase --continue.
1006
1007       The "exec" command launches the command in a shell (the one specified
1008       in $SHELL, or the default shell if $SHELL is not set), so you can use
1009       shell features (like "cd", ">", ";" ...). The command is run from the
1010       root of the working tree.
1011
1012           $ git rebase -i --exec "make test"
1013
1014       This command lets you check that intermediate commits are compilable.
1015       The todo list becomes like that:
1016
1017           pick 5928aea one
1018           exec make test
1019           pick 04d0fda two
1020           exec make test
1021           pick ba46169 three
1022           exec make test
1023           pick f4593f9 four
1024           exec make test
1025

SPLITTING COMMITS

1027       In interactive mode, you can mark commits with the action "edit".
1028       However, this does not necessarily mean that git rebase expects the
1029       result of this edit to be exactly one commit. Indeed, you can undo the
1030       commit, or you can add other commits. This can be used to split a
1031       commit into two:
1032
1033       ·   Start an interactive rebase with git rebase -i <commit>^, where
1034           <commit> is the commit you want to split. In fact, any commit range
1035           will do, as long as it contains that commit.
1036
1037       ·   Mark the commit you want to split with the action "edit".
1038
1039       ·   When it comes to editing that commit, execute git reset HEAD^. The
1040           effect is that the HEAD is rewound by one, and the index follows
1041           suit. However, the working tree stays the same.
1042
1043       ·   Now add the changes to the index that you want to have in the first
1044           commit. You can use git add (possibly interactively) or git gui (or
1045           both) to do that.
1046
1047       ·   Commit the now-current index with whatever commit message is
1048           appropriate now.
1049
1050       ·   Repeat the last two steps until your working tree is clean.
1051
1052       ·   Continue the rebase with git rebase --continue.
1053
1054       If you are not absolutely sure that the intermediate revisions are
1055       consistent (they compile, pass the testsuite, etc.) you should use git
1056       stash to stash away the not-yet-committed changes after each commit,
1057       test, and amend the commit if fixes are necessary.
1058

RECOVERING FROM UPSTREAM REBASE

1060       Rebasing (or any other form of rewriting) a branch that others have
1061       based work on is a bad idea: anyone downstream of it is forced to
1062       manually fix their history. This section explains how to do the fix
1063       from the downstream’s point of view. The real fix, however, would be to
1064       avoid rebasing the upstream in the first place.
1065
1066       To illustrate, suppose you are in a situation where someone develops a
1067       subsystem branch, and you are working on a topic that is dependent on
1068       this subsystem. You might end up with a history like the following:
1069
1070               o---o---o---o---o---o---o---o  master
1071                    \
1072                     o---o---o---o---o  subsystem
1073                                      \
1074                                       *---*---*  topic
1075
1076       If subsystem is rebased against master, the following happens:
1077
1078               o---o---o---o---o---o---o---o  master
1079                    \                       \
1080                     o---o---o---o---o       o'--o'--o'--o'--o'  subsystem
1081                                      \
1082                                       *---*---*  topic
1083
1084       If you now continue development as usual, and eventually merge topic to
1085       subsystem, the commits from subsystem will remain duplicated forever:
1086
1087               o---o---o---o---o---o---o---o  master
1088                    \                       \
1089                     o---o---o---o---o       o'--o'--o'--o'--o'--M  subsystem
1090                                      \                         /
1091                                       *---*---*-..........-*--*  topic
1092
1093       Such duplicates are generally frowned upon because they clutter up
1094       history, making it harder to follow. To clean things up, you need to
1095       transplant the commits on topic to the new subsystem tip, i.e., rebase
1096       topic. This becomes a ripple effect: anyone downstream from topic is
1097       forced to rebase too, and so on!
1098
1099       There are two kinds of fixes, discussed in the following subsections:
1100
1101       Easy case: The changes are literally the same.
1102           This happens if the subsystem rebase was a simple rebase and had no
1103           conflicts.
1104
1105       Hard case: The changes are not the same.
1106           This happens if the subsystem rebase had conflicts, or used
1107           --interactive to omit, edit, squash, or fixup commits; or if the
1108           upstream used one of commit --amend, reset, or a full history
1109           rewriting command like filter-repo[2].
1110
1111   The easy case
1112       Only works if the changes (patch IDs based on the diff contents) on
1113       subsystem are literally the same before and after the rebase subsystem
1114       did.
1115
1116       In that case, the fix is easy because git rebase knows to skip changes
1117       that are already present in the new upstream. So if you say (assuming
1118       you’re on topic)
1119
1120               $ git rebase subsystem
1121
1122       you will end up with the fixed history
1123
1124               o---o---o---o---o---o---o---o  master
1125                                            \
1126                                             o'--o'--o'--o'--o'  subsystem
1127                                                              \
1128                                                               *---*---*  topic
1129
1130   The hard case
1131       Things get more complicated if the subsystem changes do not exactly
1132       correspond to the ones before the rebase.
1133
1134           Note
1135           While an "easy case recovery" sometimes appears to be successful
1136           even in the hard case, it may have unintended consequences. For
1137           example, a commit that was removed via git rebase --interactive
1138           will be resurrected!
1139
1140       The idea is to manually tell git rebase "where the old subsystem ended
1141       and your topic began", that is, what the old merge base between them
1142       was. You will have to find a way to name the last commit of the old
1143       subsystem, for example:
1144
1145       ·   With the subsystem reflog: after git fetch, the old tip of
1146           subsystem is at subsystem@{1}. Subsequent fetches will increase the
1147           number. (See git-reflog(1).)
1148
1149       ·   Relative to the tip of topic: knowing that your topic has three
1150           commits, the old tip of subsystem must be topic~3.
1151
1152       You can then transplant the old subsystem..topic to the new tip by
1153       saying (for the reflog case, and assuming you are on topic already):
1154
1155               $ git rebase --onto subsystem subsystem@{1}
1156
1157       The ripple effect of a "hard case" recovery is especially bad: everyone
1158       downstream from topic will now have to perform a "hard case" recovery
1159       too!
1160

REBASING MERGES

1162       The interactive rebase command was originally designed to handle
1163       individual patch series. As such, it makes sense to exclude merge
1164       commits from the todo list, as the developer may have merged the
1165       then-current master while working on the branch, only to rebase all the
1166       commits onto master eventually (skipping the merge commits).
1167
1168       However, there are legitimate reasons why a developer may want to
1169       recreate merge commits: to keep the branch structure (or "commit
1170       topology") when working on multiple, inter-related branches.
1171
1172       In the following example, the developer works on a topic branch that
1173       refactors the way buttons are defined, and on another topic branch that
1174       uses that refactoring to implement a "Report a bug" button. The output
1175       of git log --graph --format=%s -5 may look like this:
1176
1177           *   Merge branch 'report-a-bug'
1178           |\
1179           | * Add the feedback button
1180           * | Merge branch 'refactor-button'
1181           |\ \
1182           | |/
1183           | * Use the Button class for all buttons
1184           | * Extract a generic Button class from the DownloadButton one
1185
1186       The developer might want to rebase those commits to a newer master
1187       while keeping the branch topology, for example when the first topic
1188       branch is expected to be integrated into master much earlier than the
1189       second one, say, to resolve merge conflicts with changes to the
1190       DownloadButton class that made it into master.
1191
1192       This rebase can be performed using the --rebase-merges option. It will
1193       generate a todo list looking like this:
1194
1195           label onto
1196
1197           # Branch: refactor-button
1198           reset onto
1199           pick 123456 Extract a generic Button class from the DownloadButton one
1200           pick 654321 Use the Button class for all buttons
1201           label refactor-button
1202
1203           # Branch: report-a-bug
1204           reset refactor-button # Use the Button class for all buttons
1205           pick abcdef Add the feedback button
1206           label report-a-bug
1207
1208           reset onto
1209           merge -C a1b2c3 refactor-button # Merge 'refactor-button'
1210           merge -C 6f5e4d report-a-bug # Merge 'report-a-bug'
1211
1212       In contrast to a regular interactive rebase, there are label, reset and
1213       merge commands in addition to pick ones.
1214
1215       The label command associates a label with the current HEAD when that
1216       command is executed. These labels are created as worktree-local refs
1217       (refs/rewritten/<label>) that will be deleted when the rebase finishes.
1218       That way, rebase operations in multiple worktrees linked to the same
1219       repository do not interfere with one another. If the label command
1220       fails, it is rescheduled immediately, with a helpful message how to
1221       proceed.
1222
1223       The reset command resets the HEAD, index and worktree to the specified
1224       revision. It is similar to an exec git reset --hard <label>, but
1225       refuses to overwrite untracked files. If the reset command fails, it is
1226       rescheduled immediately, with a helpful message how to edit the todo
1227       list (this typically happens when a reset command was inserted into the
1228       todo list manually and contains a typo).
1229
1230       The merge command will merge the specified revision(s) into whatever is
1231       HEAD at that time. With -C <original-commit>, the commit message of the
1232       specified merge commit will be used. When the -C is changed to a
1233       lower-case -c, the message will be opened in an editor after a
1234       successful merge so that the user can edit the message.
1235
1236       If a merge command fails for any reason other than merge conflicts
1237       (i.e. when the merge operation did not even start), it is rescheduled
1238       immediately.
1239
1240       At this time, the merge command will always use the recursive merge
1241       strategy for regular merges, and octopus for octopus merges, with no
1242       way to choose a different one. To work around this, an exec command can
1243       be used to call git merge explicitly, using the fact that the labels
1244       are worktree-local refs (the ref refs/rewritten/onto would correspond
1245       to the label onto, for example).
1246
1247       Note: the first command (label onto) labels the revision onto which the
1248       commits are rebased; The name onto is just a convention, as a nod to
1249       the --onto option.
1250
1251       It is also possible to introduce completely new merge commits from
1252       scratch by adding a command of the form merge <merge-head>. This form
1253       will generate a tentative commit message and always open an editor to
1254       let the user edit it. This can be useful e.g. when a topic branch turns
1255       out to address more than a single concern and wants to be split into
1256       two or even more topic branches. Consider this todo list:
1257
1258           pick 192837 Switch from GNU Makefiles to CMake
1259           pick 5a6c7e Document the switch to CMake
1260           pick 918273 Fix detection of OpenSSL in CMake
1261           pick afbecd http: add support for TLS v1.3
1262           pick fdbaec Fix detection of cURL in CMake on Windows
1263
1264       The one commit in this list that is not related to CMake may very well
1265       have been motivated by working on fixing all those bugs introduced by
1266       switching to CMake, but it addresses a different concern. To split this
1267       branch into two topic branches, the todo list could be edited like
1268       this:
1269
1270           label onto
1271
1272           pick afbecd http: add support for TLS v1.3
1273           label tlsv1.3
1274
1275           reset onto
1276           pick 192837 Switch from GNU Makefiles to CMake
1277           pick 918273 Fix detection of OpenSSL in CMake
1278           pick fdbaec Fix detection of cURL in CMake on Windows
1279           pick 5a6c7e Document the switch to CMake
1280           label cmake
1281
1282           reset onto
1283           merge tlsv1.3
1284           merge cmake
1285

BUGS

1287       The todo list presented by the deprecated --preserve-merges
1288       --interactive does not represent the topology of the revision graph
1289       (use --rebase-merges instead). Editing commits and rewording their
1290       commit messages should work fine, but attempts to reorder commits tend
1291       to produce counterintuitive results. Use --rebase-merges in such
1292       scenarios instead.
1293
1294       For example, an attempt to rearrange
1295
1296           1 --- 2 --- 3 --- 4 --- 5
1297
1298       to
1299
1300           1 --- 2 --- 4 --- 3 --- 5
1301
1302       by moving the "pick 4" line will result in the following history:
1303
1304                   3
1305                  /
1306           1 --- 2 --- 4 --- 5
1307

GIT

1309       Part of the git(1) suite
1310

NOTES

1312        1. revert-a-faulty-merge How-To
1313           file:///usr/share/doc/git/howto/revert-a-faulty-merge.html
1314
1315        2. filter-repo
1316           https://github.com/newren/git-filter-repo
1317
1318
1319
1320Git 2.26.2                        2020-04-20                     GIT-REBASE(1)
Impressum