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

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

问题描述

我不小心"向 GitHub 推送了一个提交.

I "accidentally" pushed a commit to GitHub.

是否可以删除此提交?

我想恢复我的 GitHub 存储库,就像这次提交之前一样.

I want to revert my GitHub repository as it was before this commit.

推荐答案

注意:请在下面的评论中查看 git rebase -i 的替代方案—

Note: please see an alternative to git rebase -i in the comments below—

git reset --soft HEAD^

首先,删除本地存储库上的提交.你可以使用 git rebase -i 来做到这一点.例如,如果这是您的最后一次提交,您可以执行 git rebase -i HEAD~2 并删除弹出的编辑器窗口中的第二行.

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.

然后,使用 git push origin +branchName --force

参见 Git Magic 第 5 章:历史教训 - 以及然后是一些以获取更多信息(即,如果您想删除较旧的提交).

See Git Magic Chapter 5: Lessons of History - And Then Some for more information (i.e. if you want to remove older commits).

哦,如果你的工作树很脏,你必须先做一个git stash,然后再做一个git stash apply.

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天全站免登陆