我如何删除GitHub上的提交? [英] How can I remove a commit on GitHub?

查看:662
本文介绍了我如何删除GitHub上的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否可以删除这个提交?



我想恢复我的GitHub仓库,因为它在提交之前。

注意:请在下面的评论中看到 git rebase -i 的替代选项 -

git reset --soft HEAD ^


首先,删除本地存储库中的提交。你可以使用 git rebase -i 来做到这一点。例如,如果它是你最后一次提交,你可以执行 git rebase -i HEAD〜2 并删除弹出的编辑器窗口中的第二行。然后,通过使用 git push origin + branchName
$强制推送到GitHub b $ b

请参阅 Git Magic第5章:经验教训历史 - 然后一些了解更多信息(例如,如果你想删除旧的提交)。



哦,如果你的工作树很脏,你有首先执行 git stash ,然后在 git存储之后应用


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 (i.e. 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.

这篇关于我如何删除GitHub上的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆