执行 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 --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 手册页.
这篇关于执行 git reset --hard HEAD^ 后恢复添加/暂存的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!