Delete commits from a branch in Git

后端 未结 30 2074
醉话见心
醉话见心 2020-11-21 07:17

I would like to know how to delete a commit.

By delete, I mean it is as if I didn\'t make that commit, and when I do a push in the future, my changes wi

30条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 08:02

    If you just messed up your last commit (wrong message, forgot to add some changes) and want to fix it before pushing it to a public repo why not use:

    git commit --amend -m "New message here"
    

    If you have newly staged changes they'll be combined with the last commit (that you're trying to get rid of) and will replace that commit.

    Of course if you amend a commit after you've pushed it, you're rewriting history so if you do that be sure to understand the implications.

    You can also pass the '--no-edit' option instead of '-m' if you would prefer to use the previous commit's message.

    Docs: http://git-scm.com/docs/git-commit.html

提交回复
热议问题