-2

I have committed twice and have not pushed yet. How can I undo this like though I didn't do anything. I had always thought that this would reset it:

git checkout master

but that didn't work. I also googled and found this post: Delete commits from a branch in Git

The post says that I can do

git reset --hard HEAD

However, when I do a git status it's still saying I'm behind by 2 commits

Community
  • 1
  • 1
DannyD
  • 2,732
  • 16
  • 51
  • 73
  • I looked at that as I said in my post! – DannyD Apr 21 '14 at 19:12
  • 1
    Indeed, but I don't think you read the answer properly... – Oliver Charlesworth Apr 21 '14 at 19:13
  • 1
    See also [How do you roll back (reset) a git repository to a particular commit?](http://stackoverflow.com/q/1616957/456814), [Reverting to a specific commit based on commit id with git?](http://stackoverflow.com/q/3639115/456814), and [Revert to a commit by SHA hash?](http://stackoverflow.com/q/1895059/456814). –  Apr 21 '14 at 19:18
  • see this - http://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git/23967514#23967514 – Anurag-Sharma May 31 '14 at 07:24

2 Answers2

1

git reset --hard HEAD will reset it to your HEAD.

To go 2 commits back use:

git reset --hard HEAD~2
optimus
  • 876
  • 1
  • 9
  • 19
0

If you just want to go back to what's in the remote repo, you can do:

git reset --hard origin/master

If you want to reset back to a particular local commit, just tell it the hash instead:

git reset --hard <hash of commit>

You might also first do a git fetch to make sure you know about any changes in the remote repo.

carmogan
  • 1
  • 1