With Git, how can I pull, but without causing a merge?

梦想与她 提交于 2019-12-24 11:32:01

问题


I have created a new commit, but forgot to pull before that. (I should have used git stashand 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!