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 Area | Role in Git | Address / Location | Mutability |
|---|---|---|---|
Blob | Raw file contents without filename | SHA hash in .git/objects | Immutable once written |
Tree | Directory map of names, modes, and blob SHAs | SHA hash in .git/objects | Immutable once written |
Commit | Root tree SHA, parent SHAs, author, message | SHA hash in .git/objects | Immutable history node |
| Working Tree | Editable files sitting on disk | Project folder | Mutable at any time |
| Staging Index | Candidate next commit snapshot | .git/index | Replaceable via git add |
| Local Repo | Committed object graph and branch refs | .git/ database | Append-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.
# 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 filesExample 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.
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.mdExample 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.
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 TreeExample 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.
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 diskStep 1 — Initialize a plain folder as a Git repo
Create README.md containing '# TaskFlow Notes', initialize a Git repository with git init, and inspect git status.
Show hint
Run git init after creating README.md, then run git status.
Solution available after 3 attempts
Step 2 — Promote a file from Working Tree to Index
Initialize the Git repository inside the TaskFlow workspace and promote ONLY README.md into the Staging Index while leaving src/app.ts untracked.
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
Step 3 — Complete left-to-right flow into Local Repo
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.
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
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?
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'?
echo "export const bugfix = true;" >> src/app.ts
git commit -m "fix: patch app"