Skip to content

Commit 8c22bd9

Browse files
committed
Merge branch 'en/rebase-backend'
"git rebase" has learned to use the merge backend (i.e. the machinery that drives "rebase -i") by default, while allowing "--apply" option to use the "apply" backend (e.g. the moral equivalent of "format-patch piped to am"). The rebase.backend configuration variable can be set to customize. * en/rebase-backend: rebase: rename the two primary rebase backends rebase: change the default backend from "am" to "merge" rebase: make the backend configurable via config setting rebase tests: repeat some tests using the merge backend instead of am rebase tests: mark tests specific to the am-backend with --am rebase: drop '-i' from the reflog for interactive-based rebases git-prompt: change the prompt for interactive-based rebases rebase: add an --am option rebase: move incompatibility checks between backend options a bit earlier git-rebase.txt: add more details about behavioral differences of backends rebase: allow more types of rebases to fast-forward t3432: make these tests work with either am or merge backends rebase: fix handling of restrict_revision rebase: make sure to pass along the quiet flag to the sequencer rebase, sequencer: remove the broken GIT_QUIET handling t3406: simplify an already simple test rebase (interactive-backend): fix handling of commits that become empty rebase (interactive-backend): make --keep-empty the default t3404: directly test the behavior of interest git-rebase.txt: update description of --allow-empty-message
2 parents cb2f5a8 + 10cdb9f commit 8c22bd9

25 files changed

+693
-277
lines changed

Documentation/config/rebase.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ rebase.useBuiltin::
55
is always used. Setting this will emit a warning, to alert any
66
remaining users that setting this now does nothing.
77

8+
rebase.backend::
9+
Default backend to use for rebasing. Possible choices are
10+
'apply' or 'merge'. In the future, if the merge backend gains
11+
all remaining capabilities of the apply backend, this setting
12+
may become unused.
13+
814
rebase.stat::
915
Whether to show a diffstat of what changed upstream since the last
1016
rebase. False by default.

Documentation/git-rebase.txt

Lines changed: 148 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,45 @@ See also INCOMPATIBLE OPTIONS below.
258258
original branch. The index and working tree are also left
259259
unchanged as a result.
260260

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.
264283
+
265284
See also INCOMPATIBLE OPTIONS below.
266285

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+
267295
--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.
271300
+
272301
See also INCOMPATIBLE OPTIONS below.
273302

@@ -286,7 +315,7 @@ See also INCOMPATIBLE OPTIONS below.
286315
--merge::
287316
Use merging strategies to rebase. When the recursive (default) merge
288317
strategy is used, this allows rebase to be aware of renames on the
289-
upstream side.
318+
upstream side. This is the default.
290319
+
291320
Note that a rebase merge works by replaying each commit from the working
292321
branch on top of the <upstream> branch. Because of this, when a merge
@@ -356,7 +385,7 @@ See also INCOMPATIBLE OPTIONS below.
356385
Ensure at least <n> lines of surrounding context match before
357386
and after each change. When fewer lines of surrounding
358387
context exist they all must match. By default no context is
359-
ever ignored.
388+
ever ignored. Implies --apply.
360389
+
361390
See also INCOMPATIBLE OPTIONS below.
362391

@@ -394,8 +423,9 @@ with `--keep-base` in order to drop those commits from your branch.
394423

395424
--ignore-whitespace::
396425
--whitespace=<option>::
397-
These flag are passed to the 'git apply' program
426+
These flags are passed to the 'git apply' program
398427
(see linkgit:git-apply[1]) that applies the patch.
428+
Implies --apply.
399429
+
400430
See also INCOMPATIBLE OPTIONS below.
401431

@@ -539,10 +569,11 @@ INCOMPATIBLE OPTIONS
539569

540570
The following options:
541571

572+
* --apply
542573
* --committer-date-is-author-date
543574
* --ignore-date
544-
* --whitespace
545575
* --ignore-whitespace
576+
* --whitespace
546577
* -C
547578

548579
are incompatible with the following options:
@@ -557,6 +588,7 @@ are incompatible with the following options:
557588
* --interactive
558589
* --exec
559590
* --keep-empty
591+
* --empty=
560592
* --edit-todo
561593
* --root when used in combination with --onto
562594

@@ -565,33 +597,127 @@ In addition, the following pairs of options are incompatible:
565597
* --preserve-merges and --interactive
566598
* --preserve-merges and --signoff
567599
* --preserve-merges and --rebase-merges
600+
* --preserve-merges and --empty=
568601
* --keep-base and --onto
569602
* --keep-base and --root
570603

571604
BEHAVIORAL DIFFERENCES
572605
-----------------------
573606

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:
575614

576615
Empty commits
577616
~~~~~~~~~~~~~
578617

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.
583622

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.
588629

589630
Directory rename detection
590631
~~~~~~~~~~~~~~~~~~~~~~~~~~
591632

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/
595721

596722
include::merge-strategies.txt[]
597723

0 commit comments

Comments
 (0)