Skip to content

Instantly share code, notes, and snippets.

@dyng
Created October 12, 2014 02:19
Show Gist options
  • Save dyng/1b04ae9a03c9cf761333 to your computer and use it in GitHub Desktop.
Save dyng/1b04ae9a03c9cf761333 to your computer and use it in GitHub Desktop.
Find your codes ate by git

现在假设你添加了一个新文件a.txt,内容如下:

An a file

然后git add a.txtgit 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的文件名存在。文件名信息确实真的恢复不回来,这个没办法。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment