Delete commits from a branch in Git

后端 未结 30 2072
醉话见心
醉话见心 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:52

    Forcefully Change History

    Assuming you don't just want to delete the last commit, but you want to delete specific commits of the last n commits, go with:

    git rebase -i HEAD~, so git rebase -i HEAD~5 if you want to see the last five commits.

    Then in the text editor change the word pick to drop next to every commit you would like to remove. Save and quit the editor. Voila!

    Additively Change History

    Try git revert . Revert will create a new commit that undoes the specified commit.

提交回复
热议问题