Git Blobs and Trees: From Bytes to Snapshots
What Git stores
A blob records content bytes, not a filename. A tree connects names and modes to object IDs. A commit points to a root tree. Imagine notes.txt and copy.txt with exactly the same bytes: their tree entries can reference the same blob. A directory is another tree, not a blob containing a directory listing.
Inspect a snapshot
In the chapter27 fixture, the base commit contains two identical notes and docs/start.txt. Predict whether the two note IDs match before running the commands. ls-tree shows mode, object type, ID and path. The recursive listing walks nested trees. cat-file -p on a blob emits its content; on a tree it gives a readable representation, not the raw serialized bytes.
git ls-tree basegit ls-tree -r basegit rev-parse base:notes.txt base:copy.txtgit cat-file -p base:notes.txtReason about a rename
Changing a path without changing the stored bytes can retain the blob ID while changing the containing tree and commit IDs. Mode changes can also change a tree without changing the blob. Git stores snapshots; rename detection is a comparison heuristic, not an inherent rename record in a blob.
Practice and check
Find the tree for docs and its child blob with cat-file. Compare notes.txt and copy.txt in base. Expected: the same blob ID, different paths; docs has type tree. Use a committed snapshot rather than the working file if attributes may transform bytes.
git cat-file -t base:docsgit cat-file -t base:docs/start.txtgit cat-file -s base:notes.txtCheck Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Blobs and Trees: From Bytes to Snapshots — knowledge check
Reason about Git objects, index and reference state.
Which object stores file bytes without a filename?
Two paths contain identical stored bytes. What can they share?
Which object represents directory entries?
Which command walks nested tree entries?
A rename preserves the stored bytes. What can stay identical?