Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo a git pull

Tags:

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?

like image 412
Keyo Avatar asked Jan 17 '11 23:01

Keyo


1 Answers

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.

like image 90
Gintautas Miliauskas Avatar answered Oct 08 '22 20:10

Gintautas Miliauskas