Say you're chasing a bug in the checkout flow. git blame points at a line from three months ago, and the commit message reads, in full: update logic. The code looks reasonable. What nobody remembers is why cancelled orders take a different branch here. The ticket link is dead, the reviewer has moved to another team, and the one clue left in the history says almost nothing.
Commit messages feel like paperwork when you write them, usually at the end of a task when you're tired and want to move on. The person who reads them later is often in a much worse spot: debugging production, planning a rollback, checking a security concern. This post is about writing for that person, without turning every commit into an essay.
The diff shows how, the message says why
Ask developers what a commit message should contain and the answers are fairly consistent. In a 2022 ICSE paper, Yingchen Tian and colleagues defined a good message as one that says what changed and why, then checked about 1,600 messages from five busy open source Java projects against that bar. Around 44% were missing one or the other. The most common gap, 28% on average, was the why: messages that described the change but never said what problem it solved (What Makes a Good Commit Message?).
That fits how code works. The diff already shows that a validation moved, a query changed or a flag appeared. It can't show the pressure behind the decision: a customer's odd data shape, a rollout constraint, a backwards-compatibility promise, a bug that only appears after retries. Git's own contributor guide says the goal of the log message is "to convey the why behind your change to help future developers," and asks you to explain the problem, justify the fix and mention alternatives you considered and dropped (Git SubmittingPatches). Chris Beams' widely shared guide lands on the same rule: use the body to explain what and why, and let the code show how (How to Write a Git Commit Message).
A subject line you can search for
The subject is what shows up in git log --oneline, in blame views and in release notes, so it has to carry the change. The usual conventions are short and boring in a good way:
- Imperative mood, as if you're telling the codebase what to do: "Add", "Fix", "Remove". Beams' test is that the subject should complete the sentence "If applied, this commit will..."
- About 50 characters. Git's docs call 50 a soft limit, so going over now and then is fine.
- No trailing period, and a blank line before the body.
- Name the actual thing. "update", "changes", "cleanup" and "fix bug" tell the reader an edit happened, and that's all.
Vague and specific, side by side
| Vague | Specific |
|---|---|
improve caching | Cache product summaries per locale |
refactor service | Extract refund policy from the HTTP handler |
fix bug | Reject duplicate webhook events with a known payment ID |
update logic | Skip loyalty points for cancelled orders |
If your team uses a prefix convention such as Conventional Commits (feat:, fix:), the same advice applies to everything after the prefix. fix: bug is still a vague message. It just has nicer formatting.
When the body earns its lines
Plenty of commits don't need a body. Tian's team didn't even count "fix typo a->an" as missing a why, because the reason is obvious. Small change, small message.
Write a body when the change touches behavior, data, permissions, performance or failure handling. Two to five lines usually cover it: what was wrong, why this fix, and anything the next person should watch out for.
Skip loyalty points for cancelled orders
Orders cancelled after payment still went through the points job,
so customers kept points for orders they never received. The job
now checks order status before awarding points.
Points already awarded before this change are not corrected here.
That needs a one-off backfill, tracked in BILL-412.
Look at what's in there: the problem in user terms, how the fix works, and one thing it deliberately doesn't do. A teammate who wasn't in the room can trust that commit, or revert it, without having to ask you. Link the ticket if you like, but Git's guide asks that the explanation make sense without outside resources. Ticket systems get migrated. History stays. And for decisions bigger than one commit, like picking a database or splitting a service, a commit is too small a home. Write an architecture decision record and point to it.
Commits that tell a story
A PR can hold several commits that read like steps: add a test that pins today's behavior, extract the parser into a pure function, wire the parser into the route, delete the old branch. Reviewers can see at a glance which commits are safe moves and which ones change behavior. The Linux kernel's patch guide asks for exactly this: "Separate each logical change into a separate patch," and "Solve only one problem per patch" (Submitting patches).
Small, single-purpose commits pay off again when something breaks. git bisect runs a binary search through history to find the commit that introduced a bug (git-bisect docs). It works best when each commit does one thing and builds. Landing on a 2,000-line "wip" commit tells you very little. Landing on "Extract parser into a pure function" tells you exactly where to look.
If your team squash-merges, the PR title and description usually become the commit message. Same rules, one level up: write the PR title like a subject line and keep the why in the description.
Let AI draft it, then add the why
AI tools can draft a decent subject from a diff and list the files and functions that changed. That covers the what. The why usually isn't in the diff, so the tool has to guess or leave it out. Tian's paper points at the same problem from the other side: commit message generators trained on unfiltered history learn from all the messages that already skip the why.
A workflow that holds up: let the tool propose the subject and a summary of changes, then add the two lines only you can write, which are the problem this solves and what you chose not to do. A commit message is a record of your judgment, and that part is yours to write.
None of this asks you to become a historian every time you type git commit. It asks for one clear line, and a few more when the change matters. If a single sentence in Git history has ever saved you an afternoon, you already know it's worth the minute.
Try this week
- Run
git log --oneline -20on your main repo and count how many subjects pass the "If applied, this commit will..." test. - On your next behavior change, write a body with the problem, the fix and one non-goal.
- Split your next PR into commits that each do one thing.
- If AI drafts your messages, add the why yourself before you commit.