Delete commits from a branch in Git

后端 未结 30 2117
醉话见心
醉话见心 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 07:46

    [Quick Answer]

    You have many alternatives, for example:

    • Alternative 1:

      git rebase -i ~1
      

      Change YourCommitId for the number of the commit which you want to revert back to.

    • Alternative 2:

      git reset --hard YourCommitId
      git push   --force
      

      Change YourCommitId for the number of the commit which you want to revert back to.

      I don't recommend this option because you can lost your work in progress.

    • Alternative 3:

      git reset --soft HEAD~1
      

      You can keep your work and only undo the commit.

提交回复
热议问题