What is a Tree
A tree is Git's representation of a directory. Each entry in a tree contains a file mode (permissions), an object type (blob or tree), a SHA-1 hash, and a name. Trees point to blobs for files and to other trees for subdirectories.
How it works
When Git creates a commit, it builds a tree from the current index. The root tree represents the top-level directory. Subdirectories become nested tree objects. Each tree entry looks like:
100644 blob 3b18e512... main.rs
100644 blob a9f4c1d2... lib.rs
040000 tree 7e2d0833... src/
The mode 100644 means a regular file. 040000 means a subdirectory (another tree). The hash points to the blob or tree containing the actual content.
Like blobs, trees are content-addressed. If a directory's contents do not change between commits, the tree hash is the same and no new tree object is created. Only changed directories require new tree objects.
Why it matters
Trees separate filenames from file contents. This is how Git detects renames — if a file moves from src/old.rs to src/new.rs but the content is unchanged, the blob hash is identical. Git notices the same hash appearing under a different name in the tree and reports it as a rename.
See How Git Objects Work for how blobs, trees, and commits connect into a DAG.