Reputation: 10234
The git rebase
manpage reads:
If
<upstream>
is not specified, the upstream configured inbranch.<name>.remote
andbranch.<name>.merge
options will be used;[....]
The commits that were previously saved into the temporary area are then reapplied to the current branch, one by one, in order. Note that any commits in
HEAD
which introduce the same textual changes as a commit inHEAD..<upstream>
are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped).
And indeed, when I call git rebase master
and there is a commit in master
with the same textual changes as in my local branch's history, it is ignored. However, I've found that when I call git rebase
without specifying <upstream>
(which defaults to master
), the output of git rebase
seems show the same commit not being ignored.
Here's an example to demonstrate this. Here is the git history:
A---B master
\
B' topic
B
and B'
introduce the same textual changes but have different commit messages. topic
is set up to track master
.
First, I rebase topic
while suppling <upstream>
:
$ git checkout topic
$ git rebase master
First, rewinding head to replay your work on top of it...
Nothing happens, as expected, since B
and B'
are diff-identical.
However, if I omit <upstream>
:
$ git checkout topic
$ git rebase
First, rewinding head to replay your work on top of it...
Applying: Branch: topic
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
It seems like git does not skip B'
in the second output. Can someone please explain this discrepancy?
(I'm using git version 1.9.4)
Upvotes: 6
Views: 445
Reputation: 265131
This is no longer the case (tested with latest Git 2.38.0). Here is a simple, fully-reproducible test case:
git init 26878037
cd 26878037
echo a > file
git add file
git commit -m 'initial commit'
git branch topic --track master
echo b >> file
git add file
git commit -m 'commit on master'
git checkout topic
echo b >> file
git add file
git commit -m 'commit on topic'
git rebase # defaults to upstream of topic, which is master
git log
Output of the rebase
command:
warning: skipped previously applied commit d07369f
hint: use --reapply-cherry-picks to include skipped commits
hint: Disable this message with "git config advice.skippedCherryPicks false"
Successfully rebased and updated refs/heads/topic.
Log output:
a8002a0 (HEAD -> topic, master) commit on master
7443187 initial commit
Upvotes: 2