问题
I have created a new commit, but forgot to pull before that. (I should have used git stash
and than git pull
.) Now if I git pull
, I get an additional commit "merge origin/<branch> to <branch>" (Some commits have already been pushed by some other colleagues.), which I don't want.
Is there any way to do git pull
without merging?
回答1:
git pull
is essentially git fetch
followed by git merge
, so if you want a pull without the merge, just do git fetch
.
回答2:
If you already did that commit accidentially, then follow this workflow:
- Create a new branch from the current branch (basically for making a "safety copy" of your commit).
- Reset your current branch to the commit before your commit ("deleting" the commit).
- Pull.
- Cherry-pick your commit from the backup branch to your current branch, delete the backup branch afterwards.
回答3:
All you need is git pull --rebase
来源:https://stackoverflow.com/questions/12160620/with-git-how-can-i-pull-but-without-causing-a-merge