Remove a git commit which has not been pushed

前端 未结 11 735
抹茶落季
抹茶落季 2020-12-04 04:34

I did a git commit but I have not pushed it to the repository yet. So when I do git status, I get \'# Your branch is ahead of \'master\' by 1 commi

11条回答
  •  心在旅途
    2020-12-04 04:43

    Actually, when you use git reset, you should refer to the commit that you are resetting to; so you would want the db0c078 commit, probably.

    An easier version would be git reset --hard HEAD^, to reset to the previous commit before the current head; that way you don't have to be copying around commit IDs.

    Beware when you do any git reset --hard, as you can lose any uncommitted changes you have. You might want to check git status to make sure your working copy is clean, or that you do want to blow away any changes that are there.

    In addition, instead of HEAD you can use origin/master as reference, as suggested by @bdonlan in the comments: git reset --hard origin/master

提交回复
热议问题