从远程git存储库中删除最后一次提交 [英] Remove last commit from remote git repository
问题描述
如何从远程GIT存储库中删除最后一次提交,例如我在日志中看不到它?
如果例如 git log
给了我下面的提交历史记录
A - > B-> C-> D [HEAD,ORIGIN]
到
A-> B-> C [HEAD,ORIGIN]
谢谢。 小心这样做为已经从远程存储库获取/提取/克隆的用户创建一个备用现实。但事实上,这很简单:
$ g $ git reset HEAD ^#本地删除提交
git push origin + HEAD#强制推送新的HEAD提交
如果您想在本地存储库中保留它,它来自远程,那么你可以使用:
git push origin + HEAD ^:<你的分支的名字,很有可能主和GT;
Possible Duplicate:
Rolling back local and remote git repository by 1 commit
How can I remove the last commit from a remote GIT repository such as I don't see it any more in the log?
If for example git log
gives me the following commit history
A->B->C->D[HEAD, ORIGIN]
how can I go to
A->B->C[HEAD,ORIGIN]
Thanks.
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'>
这篇关于从远程git存储库中删除最后一次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!