Skip to main content
Module 1 · Lesson 1 of 51/34 in the course~15 min
Module lessons (1/5)

Why Git stores snapshots, not diffs

Beyond Saving Endless File Copies

Early version control systems stored a baseline file followed by incremental line patches. Switching to an older branch forced the tool to replay dozens of patches sequentially just to reconstruct a folder.

Git flips that model on its head: every commit captures a complete snapshot of your project directory tree, deduplicated by content hash. If a file did not change since the previous commit, the new commit tree points straight to the existing immutable object instead of copying bytes again.

Object or AreaRole in GitAddress / LocationMutability
BlobRaw file contents without filenameSHA hash in .git/objectsImmutable once written
TreeDirectory map of names, modes, and blob SHAsSHA hash in .git/objectsImmutable once written
CommitRoot tree SHA, parent SHAs, author, messageSHA hash in .git/objectsImmutable history node
Working TreeEditable files sitting on diskProject folderMutable at any time
Staging IndexCandidate next commit snapshot.git/indexReplaceable via git add
Local RepoCommitted object graph and branch refs.git/ databaseAppend-only by default

Explore the Four Areas Live

Use the interactive simulator below to edit src/app.ts, toggle .gitignore filters, move exact file versions into the Staging Index, create immutable local commits, and sync with origin:

Example 1 — Inspecting an Uninitialized Project Folder

Before git init creates the .git database, Git refuses repository commands with fatal: not a git repository.

Bash
# Check workspace before initializing Git
ls -a
git status          # fatal: not a git repository

# Create the .git database inside the current folder
git init
ls -a               # Now shows .git alongside project files

Example 2 — Staging Files into the Index

Editing README.md only touches the Working Tree. Running git add computes the content SHA of those bytes and saves a blob in .git/objects linked from the Staging Index.

Bash
echo "# TaskFlow API" > README.md
git status          # Untracked: README.md (Working Tree only)

git add README.md   # Computes blob hash and registers README.md in Index
git status          # Changes to be committed: new file: README.md

Example 3 — Creating an Immutable Commit Snapshot

Running git commit freezes the current Staging Index into a permanent tree + commit object without grabbing unstaged Working Tree edits.

Bash
echo "export const port = 3000;" > src/server.ts
git add README.md           # Only README.md is staged!

git commit -m "docs: initialize README"
git status                  # src/server.ts remains untracked in Working Tree

Example 4 — Content Deduplication Across Commits

If Commit 1 snapshots both README.md and src/app.ts, and Commit 2 edits only src/app.ts, Git reuses the original README.md blob SHA inside Commit 2's tree automatically.

Bash
echo "export const version = 2;" > src/app.ts
git add src/app.ts
git commit -m "feat: bump version to 2"

git log --oneline           # Two commits; README.md blob exists only once on disk
Practice Stage

Step 1 — Initialize a plain folder as a Git repo

Exercise#git.m1.l1.e1
Attempts: 0Loading…

Create README.md containing '# TaskFlow Notes', initialize a Git repository with git init, and inspect git status.

Loading editor…
Show hint

Run git init after creating README.md, then run git status.

Solution available after 3 attempts

Practice Stage

Step 2 — Promote a file from Working Tree to Index

Exercise#git.m1.l1.e2
Attempts: 0Loading…

Initialize the Git repository inside the TaskFlow workspace and promote ONLY README.md into the Staging Index while leaving src/app.ts untracked.

Loading editor…
Show hint

After git init, run git add README.md rather than git add . so src/app.ts stays untracked.

Solution available after 3 attempts

Practice Stage

Step 3 — Complete left-to-right flow into Local Repo

Exercise#git.m1.l1.e3
Attempts: 0Loading…

Initialize the repository, stage both README.md and src/app.ts into the Index, and create the initial commit so the Working Tree and Index are completely clean.

Loading editor…
Show hint

Stage both README.md and src/app.ts (or git add .), then seal the commit with git commit -m "...".

Solution available after 3 attempts

Git Quiz#git.m1.l1.e4
Ready

Suppose you commit README.md and src/app.ts, then modify ONLY src/app.ts and create a second commit. How does Git store README.md in the second commit?

Answer options
Git Quiz#git.m1.l1.e5
Ready

What happens if you edit src/app.ts in the Working Tree, forget to run git add src/app.ts, and immediately run git commit -m 'fix'?

Bash
echo "export const bugfix = true;" >> src/app.ts
git commit -m "fix: patch app"
Answer options