How to undo a git pull?
Or to make it more explicit than the other answer:
git pull
whoops?
git reset --keep HEAD@{1}
Versions of git older than 1.7.1 do not have --keep
. If you use such version, you could use --hard
- but that is a dangerous operation because it loses any local changes.
To the commenter
ORIG_HEAD is previous state of HEAD, set by commands that have possibly dangerous behavior, to be easy to revert them. It is less useful now that Git has reflog: HEAD@{1} is roughly equivalent to ORIG_HEAD (HEAD@{1} is always last value of HEAD, ORIG_HEAD is last value of HEAD before dangerous operation)
git reflog show
should show you the history of HEAD. You can use that to figure out where you were before the pull
. Then you can reset
your HEAD
to that commit.
This worked for me.
git reset --hard ORIG_HEAD
Undo a merge or pull:
$ git pull (1)
Auto-merging nitfol
CONFLICT (content): Merge conflict in nitfol
Automatic merge failed; fix conflicts and then commit the result.
$ git reset --hard (2)
$ git pull . topic/branch (3)
Updating from 41223... to 13134...
Fast-forward
$ git reset --hard ORIG_HEAD (4)
Checkout this: HEAD and ORIG_HEAD in Git for more.
Find the <SHA#>
for the commit you want to go. You can find it in github or by typing git log
or git reflog show
at the command line and then do
git reset --hard <SHA#>