git GC如何在树中提交对象?

时间:2016-03-14 00:07:47

标签: git

我一直在玩git内部,并注意到树对象可以使用ls-tree / mktree格式存储提交对象:

0160000 commit <sha1>    name

我想知道git GC如何处理这种情况。

source code将此称为directory link,因为通常无效的模式位掩码0160000恰好是目录和链接位掩码的组合,而gitlink则是.gitmodules

  

是另一个git目录的链接。

环顾四周我可以看到子模块的行为建立在这个基础上(与int main() { struct node *start,*list; int i; // Allocate memory for a single node start = (struct node *)malloc(sizeof(struct node)); //??????? // The head of the list is starting node. // (This head represented by `list` will be advanced when building; // while the head represented by `start` will not be advanced // until iterating for display.) list = start; // ???????? // The starting node has no 'next' yet. // (This is not technically needed in this exact code. // The code would have been more clear with the assignment of // null to the 'next' after each malloc to start with a clean node.) start->link = NULL; // ?????????? for(i = 0; i < 10; i++) { list->item = i; list->link = (struct node *)malloc(sizeof(struct node)); list = list->link; // Move to the next (newly created) node. } // The last node has no 'next' node. Need to manually assign it // a value because it "could be anything" until properly initialized. // (Intermediate nodes have had the 'next' assigned in the loop.) list->link = NULL; //???????????? // Iterate over the list, using `start` to track the head and // keep iterating until the end of the list is reached. while(start != NULL) //?????????????? { printf("%d\n",start->item); start = start->link; // Move to the 'next' node } return 0; } 文件配对以了解其他git目录的位置),但是如果它在野外发现了一个git就会阻塞它。其他一些背景?如果提交是git对象数据库中的本地提交,该怎么办?如果这是对提交的唯一引用,那么提交不是GC,或者GC是否不将此作为参考,因为它假定它是外部的?

1 个答案:

答案 0 :(得分:1)

事实证明,这种行为并不是微妙的 - 我自己模拟它并确实提交了GC。

演示:

git init test && cd test

blob=$(echo "foobar" | git hash-object -w --stdin)
tree=$(echo "100644 blob $blob\tblob" | git mktree)
commit=$(git commit-tree $tree -m "Made sample commit.")

git prune -n # Should show the sha1's for the above objects since no ref points to them

tree_with_commit=$(echo "0160000 commit $commit\tlocal-commit" | git mktree)
git tag commit-tree $tree_with_commit # To register our objects with a ref and avoid GC

git prune -n # Same objects are up for GC––the tree_with_commit reference won't preserve them