【问题标题】:git push force on public repositorygit push force 在公共存储库上
【发布时间】:2013-11-16 06:27:28
【问题描述】:

我不小心做了一个

git push --force

在公共存储库上并恢复到以前的提交。如何解决这个问题?我的本地计算机上仍然有正确的版本,但无法将它们推送到 github 存储库,它说一切都是最新的。我知道这对我来说很愚蠢!

【问题讨论】:

    标签: git repository push


    【解决方案1】:

    放轻松,如果您在覆盖之前拥有作为原始 HEAD 的提交,您 可以 git push --force 将其恢复。只需以正确的方式告诉它git

    你得到“一切都是最新的”,因为你说得不对。当这种情况发生时,它所推动的并不是你的想法。

    找到您想要重新推送的分支,甚至只是您想要重新推送的提交 (sha)。假设你的 github 遥控器的名字是“origin”,并且假设你想修复“master”,你可以这样推回:

    git push origin the_branch:master --force
    

    甚至:

    git push origin the_sha:master --force
    

    但在您这样做之前,我建议您仔细检查差异:

    git diff the_branch..origin/master
    

    git diff the_sha..origin/master
    

    或将上面的diff 替换为rev-list 以查看将要推送的提交列表。

    【讨论】:

    • 谢谢。今晚我会睡得很好
    • 睡个好觉 ;-) 以后尽量避免--force :p
    猜你喜欢
    • 1970-01-01
    • 2010-12-17
    • 2014-06-19
    • 1970-01-01
    • 2015-04-06
    • 2010-10-11
    • 2012-08-31
    • 2014-11-11
    相关资源
    最近更新 更多