有没有办法回滚我对 Git 的最后一次推送?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6655052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to rollback my last push to Git?
提问by OpenCoderX
Possible Duplicates:
Undoing a 'git push'
可能的重复:
撤消“git push”
I have pushed some bad code, and I am the only user of the repository. How can I rollback my last commit?
我推送了一些不好的代码,我是存储库的唯一用户。如何回滚上次提交?
回答by manojlds
Since you are the only user:
由于您是唯一的用户:
git reset --hard HEAD@{1}
git push -f
git reset --hard HEAD@{1}
( basically, go back one commit, force push to the repo, then go back again - remove the last step if you don't care about the commit )
(基本上,返回一次提交,强制推送到存储库,然后再次返回 - 如果您不关心提交,请删除最后一步)
Without doing any changes to your local repo, you can also do something like:
无需对本地存储库进行任何更改,您还可以执行以下操作:
git push -f origin <sha_of_previous_commit>:master
Generally, in published repos, it is safer to do git revert
and then git push
通常,在已发布的 repos 中,这样做更安全git revert
,然后git push
回答by Ken Bloom
First you need to determine the revision ID of the last known commit. You can use HEAD^
or HEAD~{1}
if you know you need to reverse exactly one commit.
首先,您需要确定最后一次已知提交的修订 ID。您可以使用HEAD^
或者HEAD~{1}
如果您知道您需要完全反转一次提交。
git reset --hard <revision_id_of_last_known_good_commit>
git push --force