๐ฆ Git Objects - Blobs, Trees & Commits โ
๐งฑ The Building Blocks of Git
Everything in Git is built from three simple objects: Blobs, Trees, and Commits


๐บ Video Reference โ
| Resource | Link |
|---|---|
| ๐ฌ Video | Git Objects |
| ๐ Transcript | 02-git-objects.txt |
๐ง Mental Model: Git as a File System โ
"Forget about code repositories for a moment. Think of Git as a system for maintaining snapshots of a file system."
๐ฆ Object 1: Blob (Binary Large Object) โ
Definition โ
Blob vs File: Key Differences โ
| Aspect | File | Blob |
|---|---|---|
| Contains | Contents + metadata | Contents only |
| Has name? | Yes (filename) | No |
| Has date? | Yes (created, modified) | No |
| Has permissions? | Yes | No |
| Identified by | Path + name | SHA-1 hash |
Visual Representation โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FILE โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Name: hello.txt โ โ
โ โ Created: 2024-01-26 โ โ
โ โ Modified: 2024-01-26 โ โ
โ โ Permissions: 644 โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ Contents: "Hello, World!" โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ BLOB โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Contents: "Hello, World!" โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ SHA-1: aaf4c61ddcc5e8a2... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโSHA-1 Hash Explained โ
If you and I both create a blob with "Hello World", we'll get the exact same SHA-1 hash. This is how Git deduplicates data!
SHA-1 Format โ
SHA-1 hash: 20 bytes = 40 hexadecimal characters
Example: aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d
โ โ
First character Last character
Git often shows short version: aaf4c61 (first 7 chars)๐ณ Object 2: Tree โ
Definition โ
Tree Structure โ
Tree: caf7e8a...
โโโ 100644 blob f92a0b1... peak.png
โโโ 100644 blob 73d8ab2... 1.txt
โโโ 040000 tree 24601ac... subdirectoryVisual Representation โ
File Modes in Trees โ
| Mode | Type | Description |
|---|---|---|
100644 | blob | Regular file |
100755 | blob | Executable file |
120000 | blob | Symbolic link |
040000 | tree | Directory |
160000 | commit | Submodule |
Important: Names Are in Trees, Not Blobs! โ
๐ธ Object 3: Commit โ

Definition โ
What a Commit Contains โ
commit a1337e5...
โโโ tree: caf7e8a... โ Points to root tree (snapshot)
โโโ parent: 8b2f9c1... โ Previous commit (optional)
โโโ author: John <j@x.com> โ Who wrote the code
โโโ committer: Jane <j@x.com> โ Who committed
โโโ date: Mon Jan 26 2026 โ When committed
โโโ message: "Initial commit" โ Commit messageVisual Representation โ
Important: Commits Store FULL Snapshots! โ
- Changed files โ New blob created
- Unchanged files โ Just reference existing blob (no duplication!)
๐ How Changes Propagate โ
When you change a file, watch how hashes ripple upward:
Change Propagation Rules โ
| What Changed | What Gets New Hash |
|---|---|
| File contents | Blob + all parent Trees + Commit |
| Directory structure | Tree + all parent Trees + Commit |
| Only commit message | Just the Commit |
๐งช Hands-On Lab: Exploring Objects โ
Setup โ
# Create a test repository
mkdir git-objects-lab && cd git-objects-lab
git initCreate and Inspect a Blob โ
# Create a file
echo "Hello, Git Internals!" > hello.txt
# Stage it (this creates the blob)
git add hello.txt
# Find the blob
find .git/objects -type f
# Output: .git/objects/5e/1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
# Inspect the blob
git cat-file -t 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
# Output: blob
git cat-file -p 5e1c309dae7f45e0f39b1bf3ac3cd9db12e7d689
# Output: Hello, Git Internals!Create and Inspect a Tree โ
# Commit to create a tree
git commit -m "Initial commit"
# Find the tree from the commit
git cat-file -p HEAD
# Output:
# tree 8b137891791fe96927ad78e64b0aad7bded08bdc
# author ...
# committer ...
# Initial commit
# Inspect the tree
git cat-file -p 8b137891791fe96927ad78e64b0aad7bded08bdc
# Output: 100644 blob 5e1c309... hello.txtVisualize the Object Graph โ
# See all objects
find .git/objects -type f | while read f; do
hash=$(echo $f | sed 's:.git/objects/::' | tr -d '/')
type=$(git cat-file -t $hash)
echo "$hash ($type)"
done๐ฏ Quick Reference: Git Object Commands โ
| Command | Purpose | Example |
|---|---|---|
git cat-file -t <sha> | Show object type | git cat-file -t abc123 |
git cat-file -p <sha> | Pretty-print object | git cat-file -p abc123 |
git cat-file -s <sha> | Show object size | git cat-file -s abc123 |
git hash-object <file> | Compute hash | git hash-object hello.txt |
git hash-object -w <file> | Compute hash & write blob | git hash-object -w hello.txt |
๐ง Quiz: Test Your Understanding โ
1. If I create a blob with "Git is awesome" and you create the same on your computer, will we have the same hash?
โ YES! Same content always produces the same SHA-1 hash. This is content-addressed storage.
2. If we both create a tree pointing to that blob with the same name, same hash?
โ YES! Trees are also identified by their content (which includes the blobs they point to).
3. If we both create commits of that tree with message "hello", same hash?
โ NO! Commits include metadata like author, timestamp, and committer - these will differ!
4. Does Git store diffs between commits?
โ NO! Git stores full snapshots. But it's efficient because unchanged blobs are reused (not duplicated).
๐ Object Relationship Summary โ
๏ฟฝ What's Next? โ

๐ฟ Next: Branches (Lesson 03)
Now that you understand objects, let's learn how branches work. Spoiler: they're much simpler than you think - just a file containing a commit SHA!
๐ Summary โ
| Object | What It Is | Identified By | Contains |
|---|---|---|---|
| Blob | File contents | SHA-1 of content | Raw bytes |
| Tree | Directory | SHA-1 of listing | Blobs + Trees |
| Commit | Snapshot | SHA-1 of metadata + tree | Tree + parent + metadata |