Cheatsheet: Commit hygiene
Voice anchor
Section titled “Voice anchor”Git stores snapshots. Every other command is just navigating those snapshots.
Subject line rules
Section titled “Subject line rules”| Rule | Good | Bad |
|---|---|---|
| Under 72 chars | Add login form validation | (200-char rambling) |
| Imperative mood | Fix crash on empty address | Fixed crash on empty address |
| Capitalized | Add export feature | add export feature |
| No trailing period | Update README | Update README. |
| WHAT, not WHY | Refactor address-validator | Made the code better |
Commit body structure
Section titled “Commit body structure”Subject line (under 72 chars, imperative, capitalized, no period) <- blank lineFirst paragraph: WHY this change exists. What problemit solves. What the reviewer needs to know.
Second paragraph (optional): rejected alternatives andthe reasoning. Helps future readers understand why thisapproach was chosen.
Closes #1234.Atomic commit workflow
Section titled “Atomic commit workflow”# Working directory has 3 unrelated changes (files A, B, C)
git status # see all 3 changesgit add fileA.js # stage only Agit commit -m "Fix crash on empty address"
git add fileB.js # stage only Bgit commit -m "Refactor address-validator"
git add fileC.js # stage only Cgit commit -m "Add CSV export to reports"
git status # confirm clean treegit log --oneline # see 3 atomic commitsConventional Commits cheat card
Section titled “Conventional Commits cheat card”feat(scope): new feature feat(auth): add OAuth loginfix(scope): bug fix fix(api): handle null responsedocs: documentation docs: update install guiderefactor(scope): restructure refactor(checkout): extract validatortest(scope): test changes test(auth): add password edge caseschore: maintenance chore: bump depsperf(scope): performance perf(query): index user_id columnstyle: formatting style: fix indentationType indicates change kind. Scope (optional) indicates code area. Description is the imperative-mood subject.
Anti-pattern recognition
Section titled “Anti-pattern recognition”| Anti-pattern | Example | Fix |
|---|---|---|
| Vague verb | fix | Specify what was fixed: Fix crash on empty shipping address |
| Kitchen sink | Add login and fix nav and update docs | Split into 3 commits |
| End-of-day megacommit | Day's work | Commit at logical boundaries during the day |
| Fix-cascade | fix, fix again, actually fix | Test locally before committing; clean up with rebase if not pushed |
| Body-less complex | Refactor user-service (200-line diff, no body) | Add a body explaining the refactor’s motivation + design |
What’s in L4
Section titled “What’s in L4”L4 covers undoing things: git reset (move pointers, modify staging or working dir), git revert (create a new commit that undoes a prior one), git restore (discard working-dir or unstage changes), and git reflog (the safety net that lets you recover almost anything). The skills land directly on top of L3’s hygiene: knowing how to write a clean commit + how to undo a messy one closes the foundational loop.