Skip to content

Commit aa1df81

Browse files
phillipwoodgitster
authored andcommitted
rebase --keep-base: imply --no-fork-point
Given the name of the option it is confusing if --keep-base actually changes the base of the branch without --fork-point being explicitly given on the command line. The combination of --keep-base with an explicit --fork-point is still supported even though --fork-point means we do not keep the same base if the upstream branch has been rewound. We do this in case anyone is relying on this behavior which is tested in t3431[1] [1] https://lore.kernel.org/git/20200715032014.GA10818@generichostname/ Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce5238a commit aa1df81

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Documentation/git-rebase.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ leave out at most one of A and B, in which case it defaults to HEAD.
218218
merge base of `<upstream>` and `<branch>`. Running
219219
`git rebase --keep-base <upstream> <branch>` is equivalent to
220220
running
221-
`git rebase --reapply-cherry-picks --onto <upstream>...<branch> <upstream> <branch>`.
221+
`git rebase --reapply-cherry-picks --no-fork-point --onto <upstream>...<branch> <upstream> <branch>`.
222222
+
223223
This option is useful in the case where one is developing a feature on
224224
top of an upstream branch. While the feature is being worked on, the
@@ -452,9 +452,9 @@ When `--fork-point` is active, 'fork_point' will be used instead of
452452
<branch>` command (see linkgit:git-merge-base[1]). If 'fork_point'
453453
ends up being empty, the `<upstream>` will be used as a fallback.
454454
+
455-
If `<upstream>` is given on the command line, then the default is
456-
`--no-fork-point`, otherwise the default is `--fork-point`. See also
457-
`rebase.forkpoint` in linkgit:git-config[1].
455+
If `<upstream>` or `--keep-base` is given on the command line, then
456+
the default is `--no-fork-point`, otherwise the default is
457+
`--fork-point`. See also `rebase.forkpoint` in linkgit:git-config[1].
458458
+
459459
If your branch was based on `<upstream>` but `<upstream>` was rewound and
460460
your branch contains commits which were dropped, this option can be used

builtin/rebase.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12301230
die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--onto");
12311231
if (options.root)
12321232
die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--root");
1233+
/*
1234+
* --keep-base defaults to --no-fork-point to keep the
1235+
* base the same.
1236+
*/
1237+
if (options.fork_point < 0)
1238+
options.fork_point = 0;
12331239
}
12341240
/*
12351241
* --keep-base defaults to --reapply-cherry-picks to avoid losing

t/t3431-rebase-fork-point.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test_rebase () {
5050

5151
test_rebase 'G F E D B A'
5252
test_rebase 'G F D B A' --onto D
53-
test_rebase 'G F B A' --keep-base
53+
test_rebase 'G F C B A' --keep-base
5454
test_rebase 'G F C E D B A' --no-fork-point
5555
test_rebase 'G F C D B A' --no-fork-point --onto D
5656
test_rebase 'G F C B A' --no-fork-point --keep-base

0 commit comments

Comments
 (0)