执行 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 --hard HEAD~1? 但是,这个问题假设已经完成了 Git 提交.

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 "文件的状态.你可以使用

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 手册页.