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 thatM1modifiedF) git commit -a --amend --no-editto rewriteM1, which results in a new commitM2.git push -fto overwrite the remote.
In C2
- I do
git fetch. So theorigin/master == M2whileHEAD == M1
since M1 and M2 both modified F, any of the following commands will enter merge conflict state:
git merge origin/mastergit mergegit rebase origin/mastergit pull
However, the following commands does not trigger merge conflicts and set HEAD to M2
git rebasegit pull --rebase
Questions
- Is this behavior correct by design?
- What is the difference between
git rebaseandgit rebase origin/master - What does
git pull --rebasedo?
Previously, I always thought
git pullis the same asgit fetch && git merge origin/mastergit pull --rebaseis 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.