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

Atomic commits & writing meaningful history

Why One Commit = One Logical Idea

Anyone can sweep an entire afternoon into git add . && git commit -m "stuff". The bill arrives two weeks later when an urgent security fix is tangled inside a 40-file formatting commit and cannot be safely reverted without tearing down working features.

An atomic commit isolates a single coherent unit of change — every file in that snapshot serves one purpose, compiles cleanly, and carries an informative header.

PracticeCommit Shapegit revert ImpactCode Review Experience
Mega-commit (git add .)Mixes unrelated bugfixes + featuresReverts everything at oncePainful context switching
Atomic commitsOne logical change per commitClean 1-line surgical undoFast diff comprehension
Conventional prefixesfeat:, fix:, refactor:, docs:Self-indexing release notesClear grep/log scanning

Stage & Separate Changes Interactively

Walk through modifying multiple files, staging just one piece into the Index, committing it first, and reserving the rest inside the Four Areas simulator:

Example 1 — Splitting Two Edits in the Working Tree

Even when src/server.ts and src/config.ts sit modified in the same directory, stage and commit them as two crisp snapshots.

Bash
git add src/server.ts
git commit -m "fix: switch server port to 8080"

git add src/config.ts
git commit -m "feat: add dev environment config"

Example 2 — Anatomy of a Conventional Commit Subject

Keep the subject line under 72 characters in imperative mood ("add rate limiter", not "added"), prefixed by change type:

Bash
git commit -m "feat: add JWT expiration check"      # New capability
git commit -m "fix: guard against empty tax rate"   # Bug repair
git commit -m "chore: configure .gitignore defaults" # Tooling/maintenance

Example 3 — Shortcut -am Only Touches Tracked Files

git commit -am "..." stages all already-tracked modifications and commits in one step — remember it skips untracked new files (??).

Bash
echo "export const port = 9000;" > src/server.ts
git commit -am "chore: update default dev port"
# New untracked files still need an explicit git add <path>!

Example 4 — Auditing Commit Boundaries with git log --oneline

Verify after committing that every snapshot tells a coherent chronological story.

Bash
git log --oneline -n 3
# e4f2a10 feat: add dev environment config
# b9c1d02 fix: switch server port to 8080
# 7a11c33 chore: initial project setup
Practice Stage

Step 1 — Commit the server port change cleanly on its own

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

Stage ONLY src/server.ts and record an atomic commit for the port fix while leaving src/config.ts untracked in the Working Tree.

Loading editor…
Show hint

Use git add src/server.ts followed by git commit -m "...". Do NOT run git add . yet.

Solution available after 3 attempts

Practice Stage

Step 2 — Split the dirty workspace into two atomic commits

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

Replace the temptation to run git add . with two distinct atomic commits: commit src/server.ts first, then commit src/config.ts separately.

Loading editor…
Show hint

Run git add src/server.ts -> git commit -m "..." -> git add src/config.ts -> git commit -m "...".

Solution available after 3 attempts

Practice Stage

Step 3 — Build a two-commit feature stack from scratch

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

Initialize the repo, commit README.md and src/app.ts as commit #1, then create src/logger.ts containing 'export const log = true;' and commit it cleanly as a separate 'feat:' commit.

Loading editor…
Show hint

Sequence: git init -> commit README.md + src/app.ts -> create & stage src/logger.ts -> git commit -m "feat: ..."

Solution available after 3 attempts

Git Quiz#git.m1.l3.e4
Ready

Why is git commit -m 'fix: prevent negative checkout discount' considered far healthier than bundling 14 bugfixes into git commit -m 'misc fixes'?

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

You edit src/server.ts (already tracked) and create a brand-new file src/health.ts (untracked), then run git commit -am 'feat: add health endpoint'. What ends up in that new commit?

Bash
echo "export const health = true;" > src/health.ts
echo "// updated" >> src/server.ts
git commit -am "feat: add health endpoint"
Answer options