How can I remove a commit on GitHub?
I "accidentally" pushed a commit to GitHub.
Is it possible to remove this commit?
I want to revert my GitHub repository as it was before this commit.
Note: please see alternative to git rebase -i
in the comments below—
git reset --soft HEAD^
First, remove the commit on your local repository. You can do this using git rebase -i
. For example, if it's your last commit, you can do git rebase -i HEAD~2
and delete the second line within the editor window that pops up.
Then, force push to GitHub by using git push origin +branchName
See Git Magic Chapter 5: Lessons of History - And Then Some for more information (ie if you want to remove older commits).
Oh, and if your working tree is dirty, you have to do a git stash
first, and then a git stash apply
after.
git push -f origin HEAD^:master
这应该“撤销”推动。
For an easy revert if it's just a mistake (perhaps you forked a repo, then ended up pushing to the original instead of to a new one) here's another possibility:
git reset --hard 71c27777543ccfcb0376dcdd8f6777df055ef479
Obviously swap in that number for the number of the commit you want to return to.
Everything since then will be deleted once you push again. To do that, the next step would be:
git push --force
链接地址: http://www.djcxy.com/p/4066.html
上一篇: 在Git中撤消对一个文件的工作副本修改?
下一篇: 我如何删除GitHub上的提交?