Question

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

Was it helpful?

Solution

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

To go 2 commits back use:

git reset --hard HEAD~2

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top