在执行git reset --hard HEAD ^后恢复添加/暂存的文件? [英] Recovering added/staged file after doing git reset --hard HEAD^?
问题描述
我添加了一个新文件F1并更改了另一个文件F2,但随后执行了"git reset --hard HEAD ^".而且我已经丢失了对文件的所有更改.
I added a new file F1 and made changes to another file F2 but then did a "git reset --hard HEAD^" and I have lost all the changes to the files.
有没有某种方式,我可以把它们找回来?
Is there some way, I can get them back?
我确实在这里查看了一个相关的问题:如何撤消git reset-硬HEAD〜1吗?,但是,这个问题假设一个人完成了git commit.
I did look at a related question here: How can I undo git reset --hard HEAD~1? but, that question assumes that the one has done a git commit.
推荐答案
您可以(通过一些工作)在最后一个"git add < file> "处恢复文件的状态.您可以使用
You can (with some work) recover state of file at the last "git add <file>". You can use
$ git fsck --cache --no-reflogs --lost-found --dangling HEAD
,然后检查".git/lost-found/other"目录中的文件.
and then examine files in '.git/lost-found/other' directory.
请阅读 git fsck 联机帮助页
这篇关于在执行git reset --hard HEAD ^后恢复添加/暂存的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!