-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

4

2 Answers 2

1

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

To go 2 commits back use:

git reset --hard HEAD~2
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.