简体   繁体   English

从git reset --hard恢复

[英]Recovering from git reset --hard

I did (on master) 我做过(主人)

git branch mybranch 

and then (still on master) 然后(仍在主机上)

git reset --hard "commitid"

Now it seems I lost the commits after "commitid". 现在看来我在“ commitid”之后丢失了提交。 Really? 真? I lost it? 我失去了它?

Is there anyway to recover? 反正有恢复吗?

Yes, use git reflog to find the point just before the git reset. 是的,使用git reflog在git重置之前找到该点。 Then you can use something like this 然后你可以使用这样的东西

git reset --hard HEAD@{1}

它们保存在您刚创建的新分支中。

git reset --hard mybranch

Simply checkout the new branch and the commits should be there 只需签出新分支,提交就应该在那里

$ git checkout mybranch

This process is also useful when you want to move some recent commits to a new branch. 当您要将一些最近的提交移到新分支时,此过程也很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM