从远程 git 存储库中删除最后一次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8225125/
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
Remove last commit from remote git repository
提问by user1059540
Possible Duplicate:
Rolling back local and remote git repository by 1 commit
可能的重复:
通过 1 次提交回滚本地和远程 git 存储库
How can I remove the last commit from a remote GIT repository such as I don't see it any more in the log?
如何从远程 GIT 存储库中删除最后一次提交,例如我在日志中不再看到它?
If for example git log
gives me the following commit history
例如git log
,如果给我以下提交历史
A->B->C->D[HEAD, ORIGIN]
how can I go to
我怎么去
A->B->C[HEAD,ORIGIN]
Thanks.
谢谢。
回答by knittl
Be careful that this will create an "alternate reality" for people who have already fetch/pulled/cloned from the remote repository. But in fact, it's quite simple:
请注意,这将为已经从远程存储库获取/拉取/克隆的人创造一个“替代现实”。但实际上,它很简单:
git reset HEAD^ # remove commit locally
git push origin +HEAD # force-push the new HEAD commit
If you want to still have it in your local repository and only remove it from the remote, then you can use:
如果您想将其保留在本地存储库中并且仅从远程存储库中删除它,则可以使用:
git push origin +HEAD^:<name of your branch, most likely 'master'>
回答by Michael Krelin - hacker
If nobody has pulled it, you can probably do something like
如果没有人拉它,你可能会做类似的事情
git push remote +branch^1:remotebranch
which will forcibly update the remote branch to the last but one commit of your branch.
这将强制将远程分支更新到您的分支的最后一次提交。