Undo a git pull
The questions I've seen for undoing a git pull a slightly different to mine.
This is what I've done:
There is a project in directory A
(not a repo). I initialized a repository in it, added the files, but did not commit anything. Then I pulled from repository B, which overwrote a bunch of my staged files.
I was under the impression I could use git reset --hard
to undo the merge. Of course that just checked out the HEAD of the commits I had just pulled in.
I should have branched and commited something before I did this pull, hindsight is nice. Is there some way I can get my old unstaged files back?
It seems there is an answer to recovering staged files here:
Recovering added file after doing git reset --hard HEAD^
A git pull
is the same as git fetch
+ git merge
. It is the merge step that overwrote your changes. To revert to the state before the merge, use git log
to find your latest commit and then use git reset --hard 1234abcd
where 1234abcd is the hash of the desired commit.
Note that after the reset git pull
will merge the changes again. To revert the changes for good, use git revert
which will create an additional commit reversing the changes.
Either just reset to the previous HEAD (ie the commit you had in your repository, that wasn't updated from the remote), or use git reflog
. The latter displays a list of actions that were made in your repository, the git pull
command should be part of that. Simply git reset --hard X
to a state before that command.
Or just branch off the previous HEAD (you may delete/overwrite the previous branch), do your changes there and git pull again...
链接地址: http://www.djcxy.com/p/23498.html下一篇: 撤消git pull