Commit hygiene
What this lesson covers
Section titled “What this lesson covers”L3 is the discipline lesson. L2 gave you the mechanic (you can commit). L3 gives you the discipline (you can commit WELL). Three load-bearing ideas:
- A commit message is a letter to your future self and your teammates. The WHY belongs in the message because the diff already shows the WHAT.
- Atomic commits (one logical change per commit) make every other git operation easier. The staging area is the tool that lets you maintain atomicity even when working-directory changes are mixed.
- Conventional Commits is the popular convention worth knowing. When teams adopt it, history becomes skim-readable and tooling-friendly. Solo projects can use it or skip it.
By the end of L3, the reader will be able to
Section titled “By the end of L3, the reader will be able to”- Write commit messages with subject lines (50-72 chars, imperative mood, capitalized, no period)
- Write commit bodies that explain WHY, including rejected alternatives where relevant
- Apply the atomic commit principle: one logical change per commit
- Use the staging area to split unrelated working-directory changes into separate commits
- Recognize when the change should be split using the “could this be two commits?” test
- Use Conventional Commits format (type(scope): description) when team convention requires it
- Identify common anti-patterns: vague verbs, kitchen-sink commits, end-of-day mega-commits, body-less complex changes
Prerequisites
Section titled “Prerequisites”- L1 (snapshot mental model)
- L2 (mechanics of
git init,git status,git add,git commit,.gitignore) - Real project to practice on (your own, or a sandbox)
Reading map
Section titled “Reading map”L3 has more conceptual density than L2 (which was mechanics-heavy). New developers will benefit most from the worked-example sections and the anti-patterns; the Conventional Commits section is most useful when joining a team that uses it.
Experienced developers may find some of this familiar. The atomic-commit framing and the “could this be two commits?” test are useful even for those who already write good messages, naming the discipline makes it transferable.
Managers / TPMs should read the dedicated framing section near the end. Even without writing commits, the institutional-memory framing and the team-scaling-threshold observation are operationally useful.
What this lesson deliberately does not cover
Section titled “What this lesson deliberately does not cover”- Multi-file changes that need partial staging,
git add -pintroduced briefly only - Modifying past commit messages,
git commit --amenddeferred to L4 (it is technically an undo) - Interactive rebase to clean up commit history,
git rebase -ideferred to L12 (rebase vs merge lesson) - Squashing commits, deferred to L12
- Signed commits, deferred (out of T7 scope; mentioned in references only)
- Pre-commit hooks for enforcing message format, deferred (more tooling-specific than git-specific)
Estimated reading + practice time
Section titled “Estimated reading + practice time”20-25 minutes for reading. 10-15 minutes for the practice exercises (rewriting bad commits + splitting unrelated changes). Total: ~30-40 minutes.