문제

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

도움이 되었습니까?

해결책

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

To go 2 commits back use:

git reset --hard HEAD~2

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top