恢复 - git reset --hard HEAD ^ [英] restore - git reset --hard HEAD^

查看:1808
本文介绍了恢复 - git reset --hard HEAD ^的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我做了几次 git reset --hard HEAD ^ 在几个文件中丢失了一大块代码。有没有办法恢复这些提交或在这种情况下转发HEAD以前的地方,所以我可以提出我丢失的那些线?

解决方案

使用 reflog 恢复前一个HEAD的sha1。特别是, reflog,您的安全网将与您特别相关。从这篇文章中:


这个命令最常见的用法是你刚刚完成了 git reset 并将您的 HEAD 移回一些提交。但是,哎呀,你需要你在第二次提交中留下的那一点代码。废话。现在是什么?


一旦你找到了你想要返回的提交sha1,就可以使用如下所示:

  git reset --hard 0a1b2c 


Unfortunately I did several times git reset --hard HEAD^ losing a quite big chunk of code in several files. Is there a way to restore those commits or in this case to forward where the HEAD was before, so I can bring up those lines that I lost?

解决方案

Use the reflog to recover the sha1 of the previous HEAD. In particular, the article reflog, your safety net will be particularly relevant to you. From that article:

The most common usage of this command is that you’ve just done a git reset and moved your HEAD back a few commits. But oops, you need that bit of code you left in the second commit. Crap. Now what?

Once you have found the sha1 of the commit you want to go back to, use something like:

git reset --hard 0a1b2c

这篇关于恢复 - git reset --hard HEAD ^的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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