views:

470

answers:

3

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?

Thanks in advance!

Tom

A: 

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

Johan Dahlin
+5  A: 

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

knittl
doing this throws an error informing me that a file will be overwritten by merge. Is there a way to ignore this?
Thomas
Make sure your working directory is clean (git reset --hard HEAD will do that). Also, make sure the rebase is no longer in progress (git rebase --abort).
Wayne Conrad
You my friend are a life saver! Thank you :)
Thomas
Been there, done that! I think I've made every goof you can make with git. Git is a saw with no guard that makes it easy to cut your own arm off. But it also comes with an easy arm reattachment kit, and you can even attach the arm to your knee if you want.
Wayne Conrad
@wayne great metaphor :D
knittl
You can combine the checkout and reset commands and just do `git reset --hard HEAD@{1}`
Pat Notz
@pat: that will also move the branch, using reset and checkout separately you still have your old branch (which is a little bit safer if you don't know what you'r doing)
knittl
+2  A: 

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
Pat Notz