Undoing a git pull --rebase

江枫思渺然 提交于 2019-12-03 01:52:16

问题


Hey I'm new to git and I need to undo a pull, can anyone help?!? So what I've done is...

  1. git commit
  2. git stash
  3. git pull --rebase
  4. git stash pop

this created a bunch of conflicts and went a bit wrong. Now doing 'git stash list' reveals that my stash is still there. Is it possible to revert my repo back to the point just after doing git commit. So effectively my repo only contains only changes I have made and nothing new from the server?


回答1:


using git reflog you will see a list of commits HEAD pointed to in the past

using

git checkout -b after-commit HEAD@{1} # or the commit you want to recover

you create a new branch at that precise position and check it out




回答2:


Actually, to make this easier Git keeps a reference named ORIG_HEAD that points where you were before the rebase. So, it's as easy as:

git reset --hard ORIG_HEAD



回答3:


You should checkout the command

git reset --merge

That eliminates the need for a git commit; git stash before a pull (Don't know about rebase though)

The command returns a workspace with uncommitted changes to the state before a conflicting pull.




回答4:


Use git log -g and find the commit index you want to go back to, the just do git checkout index



来源:https://stackoverflow.com/questions/2213235/undoing-a-git-pull-rebase

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