1. The Object Store
Blobs, trees, and commits — the whole repository in three shapes
If you open the .git folder inside any repository and look around, the
first thing you notice is .git/objects/. That folder is the
repository. Every file you've ever committed, every directory snapshot, every commit
message — they're all in there, stored as individual files on disk.
There are only three types of object you need to understand to get the whole picture: blobs, trees, and commits. That's the entire model. (There's a fourth — the annotated tag — but it's rare and uses the same pattern as the others.)
The one-paragraph summary of Git
A blob stores the contents of one file. A tree stores a list of filenames and what blob (or sub-tree) each one points to — it's a directory snapshot. A commit stores one tree (the root directory snapshot), plus a pointer to its parent commit(s), plus author info and a message. Every object is named by the SHA-1 hash of its contents. That's Git.
Blobs — file contents, nothing else
A blob is the simplest object: a raw sequence of bytes with no filename, no permissions, no modification time. If you commit two different files with identical contents, Git stores one blob — both filenames will point at it. The filename lives somewhere else (in a tree), not on the blob itself.
Here's what a blob looks like in the object store. The content is the string
Hello, world!\n:
That's it. A blob knows nothing about where it lives or what it's called. Two files
named README.md in different branches, with identical contents, share
exactly one blob on disk. Rename a file without editing it? Same blob. Move a file
between directories? Same blob. This is why Git detects renames so cheaply — it just
notices that the same blob hash appears in two different tree entries.
Trees — directory snapshots
A tree object is a list of entries. Each entry has three pieces: a mode (file permissions or a marker that says "this is a subdirectory"), a name (the filename), and a hash (pointing at a blob or another tree).
Read that as: "in this directory there's a README.md with these contents, a
package.json with these other contents, and two subdirectories called src and docs,
whose contents are described by those trees." If you follow the src hash,
you land on another tree listing files like main.js and
utils.js. Follow those hashes and you land on blobs.
The whole repository at any point in time is a single tree — the root tree — with other trees and blobs hanging off it. It's literally a tree data structure.
Because every entry in a tree references objects by hash, the tree itself is just a list of hashes. Change one blob's content (i.e. edit a file) and its hash changes. That means the tree entry for it changes. That means the tree's own hash changes. Which ripples up to the root tree.
A tree is not a directory, it's a snapshot of one
Git's data model doesn't store "changes" — it stores complete snapshots. Every commit has a full tree of everything in the project at that moment. It only feels small on disk because of pack files (we'll get there) and because unchanged blobs are shared across commits.
Commits — trees with a message attached
A commit is where the timeline lives. It's a small object with a handful of fields:
Fix typo in getting-started.md
The word "analytical" was spelled "analitical".
Notice what a commit does not contain. There's no list of changed files. There's no diff. There's no file contents. Just a pointer to one tree (the full state of the project at this commit), a pointer to the parent commit (the previous state), and some metadata.
To show you a diff, git log -p computes the difference between this
commit's tree and the parent's tree on the fly. The diff isn't stored — it's
derived. That's why you can change commit messages with git commit --amend
or rewrite history with rebase so cheaply: you're not re-creating file contents, you're
just minting new commit objects that point at existing trees and blobs.
Commits can have multiple parents
A merge commit has two parents — one for each branch that was merged. An octopus merge (combining three or more branches at once) has more. The first commit in a repository has zero parents. Otherwise, everything has exactly one.
Every arrow in that graph points from child to parent. The graph is a Directed Acyclic Graph (DAG): directed because parent pointers go one way, acyclic because you can never be your own ancestor. The whole history of a repo — every branch, every merge — is a DAG of commit objects.
Putting it all together
One commit, expanded all the way down, looks like this:
Every one of those objects — the commit, the four trees, the five blobs — is an
individual file inside .git/objects/. The object's filename is its hash.
That's how you find anything: you know the hash, you go look it up.
Peeking at real objects
Git exposes every object through the git cat-file plumbing command. If you
have a repo handy, try this in a terminal:
$ git cat-file -p 3e8f4c7a tree 7a9f31e2b0d1c24a6e0c5b1d3e8a4b2c9f0e5d6a parent 1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c author Ada Lovelace <[email protected]> 1740000000 +0000 committer Ada Lovelace <[email protected]> 1740000000 +0000
Fix typo in getting-started.md
$ git cat-file -p 7a9f31e2 100644 blob af5626b4… README.md 100644 blob 2e1d9a0c… package.json 040000 tree c3b8f4e1… src 040000 tree 8d2a6b5f… docs
$ git cat-file -p af5626b4 Hello, world!
The command git cat-file -p pretty-prints any object. We started with a
commit hash, looked at its contents, followed the tree pointer, looked at
that, and ended at a blob whose contents are the literal string we committed.
No magic. Just pointers.
Try It Yourself — Git Object Explorer
Add files to a simulated repository, edit their contents, and create commits.
The object graph updates live — click any node to inspect the raw object,
just like git cat-file -p.
Object graph
Object inspector
What to take away
- Three object types: blobs store file contents, trees store directory listings, commits point at a tree plus parent commits.
- No diffs on disk. Git stores complete snapshots; diffs are computed when you ask for them.
- Everything is named by its hash. We haven't explained why yet — that's the next article.
- The repo is a DAG of commits, each commit pointing at a tree of trees and blobs.