如何从错误的 git push -f origin master 中恢复? [英] How can I recover from an erronous git push -f origin master?

查看:66
本文介绍了如何从错误的 git push -f origin master 中恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用 --force 选项向我的项目提交了错误的源代码.

I just committed the wrong source to my project using --force option.

可以恢复吗?我知道所有以前的分支都已使用 -f 选项覆盖,所以我可能搞砸了我以前的修订.

Is it possible to revert? I understand that all previous branches have been overwritten using -f option, so I may have screwed up my previous revisions.

推荐答案

Git 通常不会丢弃任何东西,但从中恢复可能仍然很棘手.

Git generally doesn't throw anything away, but recovering from this may still be tricky.

如果您有正确的来源,那么您可以使用 --force 选项将其推送到遥控器中.Git 不会删除任何分支,除非你告诉它.如果您确实丢失了提交,请查看 这个有用的提交恢复指南.如果您知道所需提交的 SHA-1,那么您可能没问题.

If you have the correct source then you could just push it into the remote with the --force option. Git won't have deleted any branches unless you told it to. If you have actually lost commits then take a look at this useful guide to recovering commits. If you know the SHA-1 of the commits you want then you're probably OK.

最好的做法:备份所有内容并查看本地存储库中的内容.如果可能,请在遥控器上执行相同操作.使用 git fsck 看看你是否可以恢复东西,最重要的是不要运行 git gc.

Best thing to do: Back everything up and see what is still in your local repository. Do the same on the remote if possible. Use git fsck to see if you can recover things, and above all DO NOT run git gc.

最重要的是,永远不要使用 --force 选项,除非你真的非常认真.

Above above all, never use the --force option unless you really, really mean it.

这篇关于如何从错误的 git push -f origin master 中恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆