Someone marked this as duplicates, but it does not tell why git rebase
as no conflicts while git pull
has
I have two clones of the same repo, C1
and C2
and their HEADs are both at commit M1
which has some changes to file F
.
Assume no .gitconfig
file and .git/config
for the file is the default generated by git
In C1
- I modify
F
(at the same place thatM1
modifiedF
) git commit -a --amend --no-edit
to rewriteM1
, which results in a new commitM2
.git push -f
to overwrite the remote.
In C2
- I do
git fetch
. So theorigin/master == M2
whileHEAD == M1
since M1
and M2
both modified F
, any of the following commands will enter merge conflict
state:
git merge origin/master
git merge
git rebase origin/master
git pull
However, the following commands does not trigger merge conflicts
and set HEAD
to M2
git rebase
git pull --rebase
Questions
- Is this behavior correct by design?
- What is the difference between
git rebase
andgit rebase origin/master
- What does
git pull --rebase
do?
Previously, I always thought
git pull
is the same asgit fetch && git merge origin/master
git pull --rebase
is the same asgit fetch && git rebase origin/master
But this experiment invalidates my thought.
The situation does not change even if I commit another M3
on top of M2
and push in C1
. In C2
it will still reset to M3
and the M1
is lost.