The Anatomy of a Good Commit Message

A provided sample history genuinely mixes good and bad messages. Learn to tell them apart — and to write the good kind yourself.

This lesson opens on a real, provided sample history — eight genuine commits already sitting in ~/recipes, written the way a lot of real projects actually look: some messages are clear and specific, others are genuinely useless ("fixed stuff", "asdf", "Update"). Nothing here is exaggerated for effect — this is what real, unreviewed commit history looks like.\n\nThe fix is not to go back and rewrite every bad message — real, shared history is not something you can just edit at will (that is a Certificate 3 topic, interactive rebase). What you genuinely can do: amend the most recent commit before anyone else has seen it, and — more importantly — write every commit from here on the way this lesson teaches, so future-you never has to play detective on your own work again.

Reading the Real History

git log --oneline

Eight real commits. Some are genuinely clear ("Add salt to taste note in soup recipe"); some are genuinely useless ("fixed stuff", "asdf", "Update") — the message tells you nothing about what actually changed.

What a Useless Message Actually Costs

git show fd509ba

The message says "asdf" — but the real diff shows exactly what changed: a "Serves: 24 cookies" line was added to cookies.md. That information existed the whole time; it just was not in the one place (the message) where you would normally look for it first.

Amending What You Still Can

git commit --amend -m "Add basic garden salad recipe"

The tip commit ("Update") can genuinely still be rewritten, since nothing else in history depends on its exact hash yet. Older bad messages further back cannot be edited this easily — real history rewriting is a later topic (interactive rebase, Certificate 3).

Writing One Properly, Going Forward

git commit -m "Add Belgian waffles recipe" -m "Rounds out the breakfast section alongside the existing recipes."

A real subject line (imperative mood: "Add", not "Added" or "Adding") plus a real body explaining why — exactly the shape a genuinely useful commit message takes.

Imperative mood

Writing a commit subject as a command ("Add", "Fix", "Remove") rather than as a description of what was done ("Added", "Fixed", "Adding"). This matches how git itself phrases its own generated messages (a real merge commit says "Merge branch...", not "Merged branch...") and reads naturally as "this commit will ___" when applied.

git commit --amend

Replaces the most recent commit with a new one — same parent, same position in history, but a genuinely different message (and optionally different staged content). Confirmed directly in this lab: it only ever touches the tip commit, never anything further back.

Subject vs. body

The subject (first line) is a short, real summary; the body (after a blank line) is where the why goes — context a diff alone can never provide. git commit -m <subject> -m <body> writes both in one real command.

📋 Read the Real Sample History

List the eight real commits already sitting in this repository, and spot the good ones and the useless ones.

cd ~/recipes && git log --oneline

student@lab:~$ cd ~/recipes && git log --oneline 9b10d6b (HEAD -> master) Update fd509ba asdf c764cd9 Add prep time estimates to all three recipes 1aa939c Add salt to taste note in soup recipe 56c4ee4 fixed stuff b5dba00 Add chicken noodle soup recipe cd7e65b Add ingredients list and pasta recipe 7fb33b3 Add chocolate chip cookie recipe

🔬 Find Out What "asdf" Actually Changed

Drill into the "asdf" commit directly and see its real diff — the information was always there, just not in the message.

cd ~/recipes && git show fd509ba

student@lab:~$ cd ~/recipes && git show fd509ba commit fd509ba1ba3be5fc13060db0c9986b35b296314c Author: Ada Lovelace <ada@example.com> Date: Thu Jan 1 01:10:00 2026 +0000 asdf diff --git a/cookies.md b/cookies.md index fa0cbc7..e64b315 100644 --- a/cookies.md +++ b/cookies.md @@ -1,5 +1,6 @@ Chocolate Chip Cookie Recipe Ingredients: flour, sugar, butter, chocolate chips +Serves: 24 cookies Prep time: 15 minutes

✏️ Amend the Latest Bad Message

The tip commit ("Update") can still genuinely be rewritten. Give it a real, clear message.

cd ~/recipes && git commit --amend -m 'Add basic garden salad recipe'
cd ~/recipes && git log --oneline

student@lab:~$ cd ~/recipes && git commit --amend -m 'Add basic garden salad recipe' [master 89e4953] Add basic garden salad recipe Date: Thu Jan 1 01:20:00 2026 +0000 1 file changed, 3 insertions(+) create mode 100644 salad.md student@lab:~$ cd ~/recipes && git log --oneline 89e4953 (HEAD -> master) Add basic garden salad recipe fd509ba asdf c764cd9 Add prep time estimates to all three recipes 1aa939c Add salt to taste note in soup recipe 56c4ee4 fixed stuff b5dba00 Add chicken noodle soup recipe cd7e65b Add ingredients list and pasta recipe 7fb33b3 Add chocolate chip cookie recipe

📖 Write One Properly, With a Body

Add a new recipe with a real subject and body — the pattern to use from here on.

cd ~/recipes && printf 'Belgian Waffles\n\nWhisk batter, cook in a waffle iron until golden.\n\nPrep time: 10 minutes\n' > waffles.md
cd ~/recipes && git add waffles.md
cd ~/recipes && git commit -m 'Add Belgian waffles recipe' -m 'Rounds out the breakfast section alongside the existing recipes.'

student@lab:~$ cd ~/recipes && printf 'Belgian Waffles\n\nWhisk batter, cook in a waffle iron until golden.\n\nPrep time: 10 minutes\n' > waffles.md student@lab:~$ cd ~/recipes && git add waffles.md student@lab:~$ cd ~/recipes && git commit -m 'Add Belgian waffles recipe' -m 'Rounds out the breakfast section alongside the existing recipes.' [master de60e0f] Add Belgian waffles recipe 1 file changed, 5 insertions(+) create mode 100644 waffles.md

Lab 1.2.2 complete. A real sample history studied, one bad message amended, one good one written:\n\n\n Sample history read : ✅ good and bad messages told apart\n Bad commit's real diff seen : ✅ via git show\n Tip message amended : ✅ genuinely rewritten\n New commit, subject+body : ✅ imperative mood, real reasoning\n

Enable JavaScript to run the live terminal and track your progress.