Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo a git pull?

Tags:

git

undo

pull

I would like to undo my git pull on account of unwanted commits on the remote origin, but I don't know to which revision I have to reset back to.

How can I just go back to the state before I did the git pull on the remote origin?

like image 208
Kartins Avatar asked Apr 28 '11 07:04

Kartins


People also ask

How do I revert a pull in git conflict?

In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.

How do you Unmerge last pull?

You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.


2 Answers

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)

like image 126
sehe Avatar answered Oct 20 '22 18:10

sehe


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.

like image 23
Noufal Ibrahim Avatar answered Oct 20 '22 19:10

Noufal Ibrahim