如何从错误的git push -f origin master恢复?

我只是使用--forceoption 将错误的源提交给我的项目。

是否可以还原?我知道以前的所有分支都已使用-foption 覆盖,因此我可能搞砸了以前的修订版。


侃侃无极
浏览 517回答 3
3回答

慕桂英4014372

Git通常不会丢弃任何东西,但是从中恢复可能仍然很棘手。如果您有正确的来源,则可以使用该--force选项将其推入遥控器。除非您告知,否则Git不会删除任何分支。如果您实际上丢失了提交,请查看此有关恢复提交的有用指南。如果您知道想要的提交的SHA-1,那么可能就可以了。最好的事情:备份所有内容,然后查看本地存储库中仍然存在的内容。如果可能,在遥控器上执行相同的操作。使用git fsck,看看你是否能恢复的东西,最重要的不运行git gc。最重要的是,--force除非您真的很认真,否则不要使用该选项。

SMILET

解决方案已经在这里提到# work on local mastergit checkout master# reset to the previous state of origin/master, as recorded by refloggit reset --hard origin/master@{1}# at this point verify that this is indeed the desired commit.# (if necessary, use git reflog to find the right one, and# git reset --hard to that one)# finally, push the master branch (and only the master branch) to the servergit push -f origin master
打开App,查看更多内容
随时随地看视频慕课网APP