@@ -258,16 +258,45 @@ See also INCOMPATIBLE OPTIONS below.
258
258
original branch. The index and working tree are also left
259
259
unchanged as a result.
260
260
261
- --keep-empty::
262
- Keep the commits that do not change anything from its
263
- parents in the result.
261
+ --apply:
262
+ Use applying strategies to rebase (calling `git-am`
263
+ internally). This option may become a no-op in the future
264
+ once the merge backend handles everything the apply one does.
265
+ +
266
+ See also INCOMPATIBLE OPTIONS below.
267
+
268
+ --empty={drop,keep,ask}::
269
+ How to handle commits that are not empty to start and are not
270
+ clean cherry-picks of any upstream commit, but which become
271
+ empty after rebasing (because they contain a subset of already
272
+ upstream changes). With drop (the default), commits that
273
+ become empty are dropped. With keep, such commits are kept.
274
+ With ask (implied by --interactive), the rebase will halt when
275
+ an empty commit is applied allowing you to choose whether to
276
+ drop it, edit files more, or just commit the empty changes.
277
+ Other options, like --exec, will use the default of drop unless
278
+ -i/--interactive is explicitly specified.
279
+ +
280
+ Note that commits which start empty are kept, and commits which are
281
+ clean cherry-picks (as determined by `git log --cherry-mark ...`) are
282
+ always dropped.
264
283
+
265
284
See also INCOMPATIBLE OPTIONS below.
266
285
286
+ --keep-empty::
287
+ No-op. Rebasing commits that started empty (had no change
288
+ relative to their parent) used to fail and this option would
289
+ override that behavior, allowing commits with empty changes to
290
+ be rebased. Now commits with no changes do not cause rebasing
291
+ to halt.
292
+ +
293
+ See also BEHAVIORAL DIFFERENCES and INCOMPATIBLE OPTIONS below.
294
+
267
295
--allow-empty-message::
268
- By default, rebasing commits with an empty message will fail.
269
- This option overrides that behavior, allowing commits with empty
270
- messages to be rebased.
296
+ No-op. Rebasing commits with an empty message used to fail
297
+ and this option would override that behavior, allowing commits
298
+ with empty messages to be rebased. Now commits with an empty
299
+ message do not cause rebasing to halt.
271
300
+
272
301
See also INCOMPATIBLE OPTIONS below.
273
302
@@ -286,7 +315,7 @@ See also INCOMPATIBLE OPTIONS below.
286
315
--merge::
287
316
Use merging strategies to rebase. When the recursive (default) merge
288
317
strategy is used, this allows rebase to be aware of renames on the
289
- upstream side.
318
+ upstream side. This is the default.
290
319
+
291
320
Note that a rebase merge works by replaying each commit from the working
292
321
branch on top of the <upstream> branch. Because of this, when a merge
@@ -356,7 +385,7 @@ See also INCOMPATIBLE OPTIONS below.
356
385
Ensure at least <n> lines of surrounding context match before
357
386
and after each change. When fewer lines of surrounding
358
387
context exist they all must match. By default no context is
359
- ever ignored.
388
+ ever ignored. Implies --apply.
360
389
+
361
390
See also INCOMPATIBLE OPTIONS below.
362
391
@@ -394,8 +423,9 @@ with `--keep-base` in order to drop those commits from your branch.
394
423
395
424
--ignore-whitespace::
396
425
--whitespace=<option>::
397
- These flag are passed to the 'git apply' program
426
+ These flags are passed to the 'git apply' program
398
427
(see linkgit:git-apply[1]) that applies the patch.
428
+ Implies --apply.
399
429
+
400
430
See also INCOMPATIBLE OPTIONS below.
401
431
@@ -539,10 +569,11 @@ INCOMPATIBLE OPTIONS
539
569
540
570
The following options:
541
571
572
+ * --apply
542
573
* --committer-date-is-author-date
543
574
* --ignore-date
544
- * --whitespace
545
575
* --ignore-whitespace
576
+ * --whitespace
546
577
* -C
547
578
548
579
are incompatible with the following options:
@@ -557,6 +588,7 @@ are incompatible with the following options:
557
588
* --interactive
558
589
* --exec
559
590
* --keep-empty
591
+ * --empty=
560
592
* --edit-todo
561
593
* --root when used in combination with --onto
562
594
@@ -565,33 +597,127 @@ In addition, the following pairs of options are incompatible:
565
597
* --preserve-merges and --interactive
566
598
* --preserve-merges and --signoff
567
599
* --preserve-merges and --rebase-merges
600
+ * --preserve-merges and --empty=
568
601
* --keep-base and --onto
569
602
* --keep-base and --root
570
603
571
604
BEHAVIORAL DIFFERENCES
572
605
-----------------------
573
606
574
- There are some subtle differences how the backends behave.
607
+ git rebase has two primary backends: apply and merge. (The apply
608
+ backend used to known as the 'am' backend, but the name led to
609
+ confusion as it looks like a verb instead of a noun. Also, the merge
610
+ backend used to be known as the interactive backend, but it is now
611
+ used for non-interactive cases as well. Both were renamed based on
612
+ lower-level functionality that underpinned each.) There are some
613
+ subtle differences in how these two backends behave:
575
614
576
615
Empty commits
577
616
~~~~~~~~~~~~~
578
617
579
- The am backend drops any " empty" commits, regardless of whether the
580
- commit started empty (had no changes relative to its parent to
581
- start with) or ended empty (all changes were already applied
582
- upstream in other commits) .
618
+ The apply backend unfortunately drops intentionally empty commits, i.e.
619
+ commits that started empty, though these are rare in practice. It
620
+ also drops commits that become empty and has no option for controlling
621
+ this behavior .
583
622
584
- The interactive backend drops commits by default that
585
- started empty and halts if it hits a commit that ended up empty.
586
- The `--keep-empty` option exists for the interactive backend to allow
587
- it to keep commits that started empty.
623
+ The merge backend keeps intentionally empty commits. Similar to the
624
+ apply backend, by default the merge backend drops commits that become
625
+ empty unless -i/--interactive is specified (in which case it stops and
626
+ asks the user what to do). The merge backend also has an
627
+ --empty={drop,keep,ask} option for changing the behavior of handling
628
+ commits that become empty.
588
629
589
630
Directory rename detection
590
631
~~~~~~~~~~~~~~~~~~~~~~~~~~
591
632
592
- Directory rename heuristics are enabled in the merge and interactive
593
- backends. Due to the lack of accurate tree information, directory
594
- rename detection is disabled in the am backend.
633
+ Due to the lack of accurate tree information (arising from
634
+ constructing fake ancestors with the limited information available in
635
+ patches), directory rename detection is disabled in the apply backend.
636
+ Disabled directory rename detection means that if one side of history
637
+ renames a directory and the other adds new files to the old directory,
638
+ then the new files will be left behind in the old directory without
639
+ any warning at the time of rebasing that you may want to move these
640
+ files into the new directory.
641
+
642
+ Directory rename detection works with the merge backend to provide you
643
+ warnings in such cases.
644
+
645
+ Context
646
+ ~~~~~~~
647
+
648
+ The apply backend works by creating a sequence of patches (by calling
649
+ `format-patch` internally), and then applying the patches in sequence
650
+ (calling `am` internally). Patches are composed of multiple hunks,
651
+ each with line numbers, a context region, and the actual changes. The
652
+ line numbers have to be taken with some fuzz, since the other side
653
+ will likely have inserted or deleted lines earlier in the file. The
654
+ context region is meant to help find how to adjust the line numbers in
655
+ order to apply the changes to the right lines. However, if multiple
656
+ areas of the code have the same surrounding lines of context, the
657
+ wrong one can be picked. There are real-world cases where this has
658
+ caused commits to be reapplied incorrectly with no conflicts reported.
659
+ Setting diff.context to a larger value may prevent such types of
660
+ problems, but increases the chance of spurious conflicts (since it
661
+ will require more lines of matching context to apply).
662
+
663
+ The merge backend works with a full copy of each relevant file,
664
+ insulating it from these types of problems.
665
+
666
+ Labelling of conflicts markers
667
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
668
+
669
+ When there are content conflicts, the merge machinery tries to
670
+ annotate each side's conflict markers with the commits where the
671
+ content came from. Since the apply backend drops the original
672
+ information about the rebased commits and their parents (and instead
673
+ generates new fake commits based off limited information in the
674
+ generated patches), those commits cannot be identified; instead it has
675
+ to fall back to a commit summary. Also, when merge.conflictStyle is
676
+ set to diff3, the apply backend will use "constructed merge base" to
677
+ label the content from the merge base, and thus provide no information
678
+ about the merge base commit whatsoever.
679
+
680
+ The merge backend works with the full commits on both sides of history
681
+ and thus has no such limitations.
682
+
683
+ Hooks
684
+ ~~~~~
685
+
686
+ The apply backend has not traditionally called the post-commit hook,
687
+ while the merge backend has. However, this was by accident of
688
+ implementation rather than by design. Both backends should have the
689
+ same behavior, though it is not clear which one is correct.
690
+
691
+ Interruptability
692
+ ~~~~~~~~~~~~~~~~
693
+
694
+ The apply backend has safety problems with an ill-timed interrupt; if
695
+ the user presses Ctrl-C at the wrong time to try to abort the rebase,
696
+ the rebase can enter a state where it cannot be aborted with a
697
+ subsequent `git rebase --abort`. The merge backend does not appear to
698
+ suffer from the same shortcoming. (See
699
+ https://lore.kernel.org/git/
[email protected] / for
700
+ details.)
701
+
702
+ Miscellaneous differences
703
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
704
+
705
+ There are a few more behavioral differences that most folks would
706
+ probably consider inconsequential but which are mentioned for
707
+ completeness:
708
+
709
+ * Reflog: The two backends will use different wording when describing
710
+ the changes made in the reflog, though both will make use of the
711
+ word "rebase".
712
+
713
+ * Progress, informational, and error messages: The two backends
714
+ provide slightly different progress and informational messages.
715
+ Also, the apply backend writes error messages (such as "Your files
716
+ would be overwritten...") to stdout, while the merge backend writes
717
+ them to stderr.
718
+
719
+ * State directories: The two backends keep their state in different
720
+ directories under .git/
595
721
596
722
include::merge-strategies.txt[]
597
723
0 commit comments