1

I've explored a lot about the 3 commit model of the git internals and in the diagram,it's shown that tree object type is pointing to the other trees as well, but when I do git cat-file -p 'sha-hash', It tells that tree is pointing to the blobs only. Please refer to the screenshot attached. Please help me with a screenshot where tree is pointing to some other tree or tell me any use case which I may be missing.

j

2 Answers 2

3

If a file's name is a/b/c/f.ext it will be stored in a commit as:

  • at the level of the commit: a tree containing a subtree named a
  • at the level of the subtree named a: a tree containing a subtree named b
  • at the level of the subtree named b: a tree containing a subtree named c
  • at the level of the subtree named c: a tree containing a blob named f.ext

Hence, from the top, we simply string together the names of each higher level tree to arrive at the file's actual name, a/b/c/f.ext.

None of this really matters while using the file, since the important version of the file is the one in the index, and that one is named a/b/c/f.ext (with slashes in the name). It only matters when reading trees into the index (git read-tree), and when writing the index to a series of trees (git write-tree).

1
  • Thank you so much. I was missing this use case about the directory.
    – echobash
    Commented Feb 16, 2020 at 14:19
1

I think @torek has explained it pretty well. Also, I would like to add on that this all storage is done in the form of SHA1 hashes, the blob(binary large object) stores file contents while the trees store, in maybe vague terms, the file name and subtrees inside of it.

This is a pretty good guide to the internals of Git, you might as well take a look at it.

Cheers!

Not the answer you're looking for? Browse other questions tagged or ask your own question.