如“Git Internals - Git Objects”中所述,每次更改文件内容并将其添加到缓存中时,您都会执行以下操作:
git hash-object -w test.txt
将其存储到存储的对象中。
我只是为一个文件连续做了两个git add,然后是一个:
C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo\.git>gfind -mmin -10 -print
.
./index
./objects/4f
./objects/4f/76d586459ec6ffc42257bb4c61d5422051cb10
./objects/61
./objects/61/24401794e7fee613f5a56593a0a8a059b2627a
(注意-mmin 参数仅用于查找自最近 10 分钟以来修改过的文件)
我可以在每个 git add 之后列出相同的 sha1,并带有:
git rev-parse :0:abstractNode_test.go
参见git rev-parse(和“What does git rev-parse do?”):在索引中添加文件仅是阶段 0(阶段 1、2 和 3 在合并期间用于记录仍在索引中的共同祖先,源和目标版本)。
如果我存储这两个 blob 的内容:
C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo>
git cat-file -p 4f76d586459ec6ffc42257bb4c61d5422051cb10 > a
git cat-file -p 6124401794e7fee613f5a56593a0a8a059b2627a > b
(请注意我如何将 blob 路径的“4f/”部分与路径的其余部分连接起来以获得完整的 sha1)
a 和 b 之间的差异确实给了我为同一个文件添加到索引中的额外位。
torek 还提到了in the comments:
另一种(我认为更简单)的方式:git fsck --lost-found.
悬空的 blob 对象在 .git/lost-found/other/ 中结束,并且已经是 cat-file -p-ed。
您确实会发现您在最后一个最终提交之前所做的所有 git add。
就我而言,只有一个出现:
C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo\.git\lost-found\other>dir
Volume in drive C has no label.
Volume Serial Number is D866-48E1
Directory of C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo\.git\lost-found\other
25/01/2014 17:31 <DIR> .
25/01/2014 17:31 <DIR> ..
25/01/2014 17:31 16 873 4f76d586459ec6ffc42257bb4c61d5422051cb10