If you have uncommitted changes that you want to discard, use this:
$ git reset --hard
which is equivalent to
$ git reset --hard HEAD
This removes all the local uncommitted changes. If you want to remove some offending commits from your local branch, try rewinding it:
$ git reset --hard HEAD^ #moves HEAD back by one commit
or e.g.
$ git reset --hard HEAD~3 #moves HEAD back by 3 commits
Use these with caution, as you won't be able to undo these operations. Once you're done cleaning up your local branch, use git pull
to get the latest code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…