How to delete the last n commits on Github and locally?

后端 未结 3 1648
悲&欢浪女
悲&欢浪女 2020-12-04 05:45

I\'m trying to delete the last 2 commits from one of my GitHub repositories. I\'ve tried as suggested here : git push -f origin HEAD^^:master. It seems that it

3条回答
  •  遥遥无期
    2020-12-04 06:00

    If you want to remove the 2 (two) last commits, there is an easy command to do that:

    git reset --hard HEAD~2
    

    You can change the 2 for any number of last commits you want to remove.

    And to push this change to remote, you need to do a git push with the force (-f) parameter:

    git push -f
    

    However, I don't recommend to do any git command with -f or --hard options involved if there are new commits on remote (Github) after this commits that you want to remove. In that case, always use git revert.

提交回复
热议问题