f来源大师'任何方式来恢复?

我提交了'git push -f origin master',它删除了我以前的所有提交。 有什么办法可以恢复它们,或者至少可以显示我以前的所有提交?


你可以试试这个:

$ git reflog                   # show working tree, copy the last commit-hash that have all codes
$ git checkout <commit-hash>   # checkout to that commit, now you've all codes
$ git checkout -b new-master   # create a new branch named new-master & checkout.
$ git branch -D master         # delete your local master branch
$ git checkout -b master       # create master from current commit and checkout to master
$ git push -f origin master    # push all the codes to remote  

使用git reflog查看缺少的提交。

然后,找到你想要的提交并使用git reset来重置它们。

重置已删除的提交后,使用git push origin master将更改推送到原点


您可以使用来自本地git reflog或远程存储库的reflog,并找到您想要恢复的提交;

git reflog //at local level
git reflog show remotes/origin/master // at remote level: 

reflog以反向时间顺序或时间顺序显示对HEAD的所有更改的列表。 第一列中的值是执行右侧行为后的HEAD值。 所以你可以通过检查它的散列来找到提交散列并检出你想要返回你的仓库的提交

git checkout <commit-hash>

从提交中创建临时分支

git checkout -b new-master

将它推回到远程存储库。

git push -f origin master

但是,这将修复您的远程主服务器,但请注意,您的本地主服务器仍然是引入了破坏性更改的主服务器,因此如果您不需要更改,可以使用以下命令将其删除。

git branch -D master , 

或者你可能需要做一些事情,比如挑选所有丢失的提交。

PS:你也可以找到更适合于恢复丢失的提交的git fsck

链接地址: http://www.djcxy.com/p/3969.html

上一篇: f origin master' any way to restore?

下一篇: How to modify master in Git (in this situation)