Sub topic 5
Writing a clear, short description
This chapter assumes you can write commits with git commit, read git log, and know the basic structure of a conventional commit: type(scope): description. It covers the description, the part after the colon and space. The description is what most people read, so it carries most of the value of the convention.
What the description does
The description is the short summary on the first line of the commit message. The Conventional Commits 1.0.0 specification requires it immediately after the type/scope prefix, with a colon and a space in between.
The same line shows up in many places:
git log --onelineoutput- Changelog entries generated by release tools
- Pull request titles after a squash merge
- The subject line in email patches and code review tools
- Blame and bisect output, when you look for the change that broke something
Most of these views truncate long lines or show only the first line. A reader who sees only the first line should still learn what changed.
Rules from the specification and common practice
The specification is short on style. It requires that the description exists and follows the prefix. It does not set a length limit or a grammar. The rules below come from the specification plus widely used Git practice, and linters such as commitlint enforce some of them.
| Rule | Example | Why |
|---|---|---|
| Use the imperative mood | `add`, not `added` or `adds` | Matches messages Git generates, such as "Merge branch" and "Revert". |
| Start in lowercase | `fix: handle empty input` | `config-conventional` rejects some capitalized subjects. |
| No trailing period | `fix: handle empty input` | Saves a character and avoids noise in lists. |
| Keep the full first line near 50 to 72 characters | See below | Avoids truncation in terminals and tools. |
| Describe the change, not the file | `fix: reject negative page numbers` | The diff already shows which files changed. |
A handy test for the imperative mood is to complete this sentence: "If applied, this commit will ___." The description should fit the blank.
fix: prevent crash when the config file is emptyfits: "this commit will prevent crash when the config file is empty."fix: prevented crash on empty configdoes not fit.
Note that the length limit counts the whole first line, including the type and scope. A long scope leaves less room for the description.
Good and bad descriptions
A weak description names an activity. A strong one names the effect.
| Weak | Problem | Better |
|---|---|---|
| `fix: bug` | Says nothing about which bug | `fix: stop crash when config file is empty` |
| `feat: updates` | Not specific | `feat: add dark mode toggle to settings page` |
| `fix: fixed the thing in utils.py` | Past tense, names a file, vague | `fix: round prices to two decimals` |
| `chore: changes` | Tells the reader nothing | `chore: pin node version to 20 in CI` |
| `refactor: Refactor the parser.` | Repeats the type, capitalized, ends in a period | `refactor: split tokenizer from parser` |
| `feat: add support for the new feature that allows users to export their data in CSV format` | Too long | `feat: export user data as CSV` |
Repeating the type is a common error. refactor: refactor the parser wastes space because the type already says it. Use the saved characters for the specific change.
Describe the user-visible result when it matters
The type decides who cares about the commit. For feat and fix, release tools usually copy the description into a changelog, so write it for someone who uses the software, not only someone who reads the code.
fix: use the cached token instead of requesting a new oneThat describes the mechanism. A changelog reader may prefer the symptom:
fix: stop logging users out after ten minutesFor refactor, test, ci, and chore, the audience is other developers, so a mechanism description is fine. Pick wording based on who reads the line.
When the description is too long
If you cannot summarize a change in one short line, there are usually two possible causes.
- The commit does too much. Split it into several commits, each with its own type. A change that adds a feature and fixes an unrelated bug should be two commits.
- The detail belongs in the body. Keep the description short and move the reasoning to the body, separated by a blank line.
fix(cache): stop serving stale entries after a config reload
The cache key ignored the config version, so entries created before
a reload were still returned. The key now includes the version.
Refs: #311The description answers "what changed". The body answers "why" and "how".
Check your descriptions with a script
You can check part of these rules automatically. The following script reads recent first lines and reports ones that break the common rules: a trailing period, an uppercase first letter, a past-tense ending such as "ed" on the first word, or a line over 72 characters.
#!/bin/sh
# check-descriptions.sh: report style problems in recent commit subjects
count="${1:-20}"
git log -n "$count" --format='%h %s' | while read -r hash subject; do
# remove the "type(scope)!: " prefix to get the description
desc=$(printf '%s' "$subject" | sed -E 's/^[a-z]+(\([^)]*\))?!?: //')
if [ ${#subject} -gt 72 ]; then
echo "$hash: first line is longer than 72 characters"
fi
case "$desc" in
*.) echo "$hash: description ends with a period" ;;
esac
case "$desc" in
[A-Z]*) echo "$hash: description starts with a capital letter" ;;
esac
case "$desc" in
*ed\ *|*ed) first=${desc%% *}
case "$first" in
*ed) echo "$hash: first word '$first' may be past tense" ;;
esac ;;
esac
doneRun it with sh check-descriptions.sh 30 to check the last 30 commits. The past-tense check is a heuristic. It flags words such as "fixed" but also words such as "speed", so treat its output as a prompt to look, not as a verdict.
Enforcing description style with commitlint
The @commitlint/config-conventional ruleset covers several of these points. It limits the header length to 100 characters by default, rejects an empty subject, and rejects subjects that end with a period. It also rejects certain capitalization styles in the subject. Teams that want a tighter limit can override it:
// commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'header-max-length': [2, 'always', 72],
'subject-full-stop': [2, 'never', '.'],
'subject-empty': [2, 'never'],
},
};In each rule, the first number is the severity (0 disables, 1 warns, 2 fails), the second says whether the rule applies "always" or "never", and the third is the value. A linter cannot check whether a description is meaningful. fix: bug passes every mechanical rule, so review still matters.
Edge cases
- Non-English teams. The spec does not require English. Agree on one language per repository so that searching history works.
- Issue numbers. Put them in a footer such as
Refs: #482, not in the description. Numbers in the description use up space and break the imperative flow. - Emoji. Avoid them in the prefix. They are not part of the format and break pattern checks such as the regular expression in the
commit-msghook. - Capitalized names. A proper noun or acronym can start the description, such as
fix: URL parser drops query strings. Linter rules about case may reject this. Decide as a team whether to relax thesubject-caserule. - Merge commits. Git writes
Merge branch ...itself, which does not follow the format. Most teams exempt merge commits from linting or avoid them by using squash merges.
Searching by description
Because descriptions are short and consistent, plain git log works as a search tool.
# find commits that mention "cache" in the first line
git log --oneline --grep='cache'
# find fixes that mention "crash"
git log --oneline --grep='^fix.*crash'These queries only work well when descriptions name the specific symptom. fix: bug cannot be found by anyone looking for a crash.
Exercise
Rewrite this commit message so that it follows the guidance in this chapter: Fix: Fixed the bug where users couldn't log in after the password was changed. Give the full corrected first line, and name each rule you applied.
Show answer
fix: allow login after a password change. Rules applied: the type is lowercase, as required by the common conventional ruleset; the description is in the imperative mood ("allow", not "fixed"); it does not repeat the type ("fix: fixed"); it starts in lowercase; it has no trailing period; it names the specific effect instead of the vague word "bug"; and the whole line is under 72 characters. Another wording such as fix: accept new password on first login is also fine if it describes the actual bug.
Exercise
A commit adds a CSV export button and also corrects a typo in the README. A teammate suggests the message feat: add CSV export and fix README typo. What is wrong with it, and what would you do instead?
Show answer
The description joins two unrelated changes with "and", which is a sign the commit should be split. The two changes also have different types: feat for the export button and docs for the typo. Make two commits: feat: add CSV export button to reports page and docs: fix typo in README. This keeps the changelog accurate, because only the feat commit produces a MINOR version bump, and it keeps each commit easy to revert.