Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better explanation of trees #25

Open
AndrewGibb opened this issue Jul 20, 2022 · 1 comment
Open

Better explanation of trees #25

AndrewGibb opened this issue Jul 20, 2022 · 1 comment

Comments

@AndrewGibb
Copy link

Thanks for the great book!

Having read the book, I find my understanding of trees still quite fuzzy. It might be helpful to have an entry in the first page glossary describing what they are. Specifically, I wonder:

  • Do git trees hold anything other than blobs?
  • If not, how do trees interconnect, as illustrated at the bottom of "The beauty of commits"? Do they inherit their connections from the owning commit?
  • My understanding is that a commit contains exactly one tree which contains one or more blobs (otherwise the commit would be empty?) If that is the case, then why does the tree pointed to by the first commit in the digram at the bottom of "The beauty of commits" not point to any blobs?
  • Why are they called trees? The seem to just be buckets of blobs. I see that they can be arranged in a tree, but nothing here demonstrates tree-like behaviour.
@Paciupa
Copy link

Paciupa commented Nov 15, 2022

"The beauty of commits" section has everything, but in an abbreviated form. So I think you can find answers in Tree Objects section of ProGit book.

Do git trees hold anything other than blobs?

Not blobs themselves, but refs to blobs and trees.

tree object
An object containing a list of file names and modes along with refs to the associated blob and/or tree objects. A tree is equivalent to a directory.

Do they inherit their connections from the owning commit?

No, the opposite. As you can see in the picture, the arrow points from the commit to the tree. So the commit object refers to the tree object, the tree object refers to other trees and blobs, and trees don't have any information about commits.

My understanding is that a commit contains exactly one tree

Yes, commit object refers to top-level tree object.

If that is the case, then why does the tree pointed to by the first commit in the digram at the bottom of "The beauty of commits" not point to any blobs?

It's directory with subdirectories, without any files, But there are some files in these subdirectories.

Why are they called trees? The seem to just be buckets of blobs. I see that they can be arranged in a tree, but nothing here demonstrates tree-like behaviour.

Because they seem like branches on the tree: they may refer to smaller branches (trees in Git) and/or to leaves (blobs in Git).

You can try all of these things by yourself using plumbing commands, especially cat-file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants