现在假设你添加了一个新文件a.txt
,内容如下:
An a file
然后git add a.txt
,git reset --hard
,恢复到初始状态。
这时运行git fsck
的结果如下:
Checking object directories: 100% (256/256), done.
dangling blob 751b0aae0e88fc095ff05e3b697402f5721d3ae6
751b0aae0e88fc095ff05e3b697402f5721d3ae6
就是a.txt
经过 hash 以后的值,查看内容可以使用
~ > git cat-file -p 751b0aae0e88fc095ff05e3b697402f5721d3ae6
An a file
大致原理就是这样,--lost-found
选项就是自动把a.txt
输出到.git/lost-found/other
下,以751b0aae0e88fc095ff05e3b697402f5721d3ae6
的文件名存在。文件名信息确实真的恢复不回来,这个没办法。