【发布时间】:2012-06-28 20:36:24
【问题描述】:
我对 git add 操作很好奇, 所以我做了一些测试。
创建索引
1. git init
2. mkdir mydir
3. echo "hello" > mydir/hello
4. find .git/objects ==> nothing
5. git add .
6. find .git/objects ==> only find one file ,by cat-file, I am sure it is hello
做一些改变
7. rm mydir/hello
取回文件
8. git checkout mydir/hello
9. ls mydir/hello ==> hello is back
我的疑问是:
当我做'git add .' 时,只创建一个blob,而不是创建一棵树来记录直接的'mydir'。那么,git checkout mydir/hello 怎么能找到 blob 呢?
【问题讨论】:
-
我相信这些树是单独在
.git/index中构建的,因为这通常会在实际提交之前发生变化。 -
您可能会发现 Pro Git 书籍中关于 "Git Internals" 的部分很有趣,尤其是“树对象”。它似乎很好地遍历了 git 的存储。
-
Git Internal 只是给出了一个没有目录的例子。就不详细解释了。
标签: git git-checkout git-add