How to Write a Good Commit Message (And Why It Matters More Than You Think)

Tested by TNT Review — record TNT-TEST-2026-10-05-030, 5 October 2026. We ran a real search against a repo with 3 commits (2 vague, 1 descriptive) and the real result is in Verification.

The problem

“fix” and “stuff” as commit messages feel harmless in the moment — you know what you changed, right now. Six months later, searching your project’s history for the commit that touched login, you’ll find nothing, because nothing in those messages says “login.”

Expected outcome

By the end of this guide you will understand exactly what a commit message is actually FOR — being found later, by you or someone else — demonstrated with a real search that only works on one of three real commits.

Requirements and costs

  • Git, already installed if you’re using it at all.
  • Cost: free.

Step-by-step implementation

  1. Write the subject line as a specific statement of what changed, not a category — “Fix null pointer when email field is empty,” not “fix” or “bugfix.”
  2. Include the area or feature name somewhere in the message, even briefly — it’s the word future-you will actually search for.
  3. Explain WHY in the body, if it’s not obvious from the diff alone — the diff already shows WHAT changed; a message that only repeats that adds nothing.
  4. Search your own history periodically with git log --grep="keyword" to see whether your own past messages are actually findable.

A real example

Three real commits in order: “fix,” “stuff,” “Fix null pointer exception in user login when email field is empty.” Searching for anything related to login:

$ git log --oneline --grep="login"
b1a0884 Fix null pointer exception in user login when email field is empty

Only the third commit is found — not because the other two are unrelated, but because nothing in their messages says what they actually touched.

Verification and troubleshooting

What we tested, on 5 October 2026 (record TNT-TEST-2026-10-05-030): created a real local repo with 3 commits (“fix,” “stuff,” and one descriptive message mentioning “login”), then ran git log --oneline --grep="login" and confirmed it returned exactly 1 of the 3 real commits — the descriptive one — proving message quality directly determines whether --grep can find it later, not a hypothetical claim.

Troubleshooting:

  • You already have a history full of vague messages. You generally can’t (and shouldn’t) rewrite published history just to fix old messages — focus on new commits going forward; git blame plus reading the actual diff still works for old ones, just more slowly.
  • git log --grep finds nothing for a term you’re sure is relevant. By default it searches the message only, not the diff content — use git log -S"search term" instead to search for a string’s actual addition/removal in the code.
  • Your team disagrees on commit message format. Agree on a minimum bar (a specific subject line, under ~72 characters) rather than a rigid template — consistency matters less than each message actually being specific.

Limitations and alternatives

Good commit messages don’t replace code comments or documentation — they explain the change’s intent at the time it was made, which comments describing current behavior don’t capture. Tools like conventional commits add structured prefixes (fix:, feat:) on top of this same principle, useful for automated changelog generation, not a substitute for the message actually being specific.

Is there a paid version?

Not applicable. This is a free, built-in git feature and a writing habit, not a product.

Leave a comment