Sub topic 5
Writing a clear, short description
This chapter covers the description, the short text after the colon on the first line of a conventional commit. It assumes you know the basic commit workflow (add, commit, log) and that you have seen the type(scope): description structure from the previous chapters.
Why the description matters most
The description is the part of a commit that people read most often. It appears in git log --oneline, in pull request lists, in changelogs and in release notes. A reader scanning history sees the type, the scope and the description, and usually nothing else.
The specification requires only that the description follows the colon and a space, and that it is a short summary of the code changes. The rest is convention. The guidelines below are the ones most teams settle on.
Rules of thumb
- Use the imperative mood. Write "add", not "added" or "adds". A good test is to complete the sentence "If applied, this commit will ...".
- Start in lowercase. The type already begins the line, so the description reads as a continuation of it. Many linters enforce this.
- Skip the final period. The line is a title, not a sentence in a paragraph.
- Aim for 50 characters, and stay under 72. Shorter lines stay readable in
--onelineoutput and in terminals. Count the type and scope toward the limit. - Say what changed and why it matters. Describe the effect, not the file you touched.
- Keep to one change. If the description needs "and", consider splitting the commit.
Before and after
The table shows common weak descriptions and stronger replacements.
| Weak | Stronger | Problem fixed |
|---|---|---|
| `fix: bug` | `fix: prevent crash when the config file is empty` | Names no specific problem |
| `feat: added new stuff` | `feat(parser): add support for array literals` | Past tense and vague wording |
| `chore: update files.` | `chore: bump eslint to 9.0` | Says nothing about the change, and ends with a period |
| `fix: changes to login.js` | `fix(auth): reject expired session tokens` | Names a file, not a behavior |
| `feat: add search and fix footer and update docs` | Three separate commits | Bundles unrelated changes |
A worked example
Suppose you fixed a bug where saving an empty form sent a request with a null body. A first draft might be:
fix: fixed the form thingWork through the checks:
- Mood: "fixed" becomes "fix", but the type is already
fix, so repeating the verb adds nothing. - Specificity: which form, and what went wrong?
- Effect: what does the user or caller now see?
A better version:
fix(forms): skip the request when the form is emptyIt is 51 characters, in the imperative mood, lowercase, and without a period. A reader knows the area (forms) and the new behavior without opening the diff.
Do not repeat the type
The type already says what kind of change this is. Avoid descriptions such as fix: fix crash or docs: update documentation. Use the space for information the type does not carry.
docs: update documentation
docs: explain how to configure proxy settingsThe second line tells the reader what the documentation now covers.
Checking length in practice
You can find overlong first lines in your own history with a short command:
git log --format='%h %s' | awk 'length($0) > 80 { print }'The %s placeholder prints the subject line, which is the first line of the message. The 80 leaves room for the abbreviated hash and a space. Change the number to fit your team's limit.
Common errors
- Vague verbs. "update", "change" and "improve" say little. Prefer a verb that names the action, such as "reject", "cache" or "rename".
- Describing the process. "fix after review comments" tells nothing about the code. Describe the result instead.
- Putting detail in the description. If you need the reason or the context, move it to the body, which a blank line separates from the description.
- Mixing languages or tenses within a repository. Pick one and let linting hold the line.
Exercise
Rewrite this commit message so that it follows the guidelines in this chapter: feat(cart): Added the ability for users to apply discount codes at checkout. Give the result and name each problem you fixed.
Show answer
feat(cart): add discount code support at checkout. Fixes: "Added" changed to the imperative "add"; capital letter changed to lowercase; trailing period removed; wordy phrase "the ability for users to apply" shortened, so the line drops from about 78 characters to 51 and stays within the limit.
Exercise
Why is fix: fix login bug a weak commit message, and what would you write if a missing null check caused the crash on the login screen?
Show answer
The description repeats the type and does not say what failed or where. A stronger message is fix(login): handle missing user profile on sign-in, which names the area and the behavior. Any specific, imperative description of the null-check fix is acceptable.