Sub topic 6
Using the body and footers
This chapter assumes you can write a one-line conventional commit (type, optional scope, description) and use git commit and git log comfortably. The description alone says what changed. The body and footers carry the rest: why it changed, what the reader should watch for, and machine-readable links to issues, people, and breaking changes.
Where the body and footers sit
A conventional commit has up to three blocks after the first line. Blank lines separate them.
A complete message looks like this:
fix(auth): stop refreshing tokens during logout
The refresh timer kept running after logout began. It requested a new
token, which re-created the session we had just destroyed.
The timer is now cancelled before the session is cleared.
Fixes: #301
Reviewed-by: Dana OrtizThe body is optional. The footers are optional. You can have footers without a body, as long as a blank line separates them from the description.
fix: reject empty usernames
Refs: #77The body
The body explains the change in free-form text. The specification sets almost no rules for it:
- It starts one blank line after the description.
- It can contain any number of paragraphs, and each paragraph is separated by a blank line.
- It has no required syntax. Lists, code snippets, and links are allowed.
What belongs in a body
The diff already shows what changed line by line. The body should hold what the diff cannot show:
- The motivation. What was wrong, or what need prompted this?
- The approach. Why this solution and not an obvious alternative?
- Side effects. Does behavior change for callers, performance, or data?
- Context that will not survive. Benchmark numbers, an error message, or the decision reached in a meeting.
Keep the description in the imperative mood and short. Put the explanation in the body.
Line length and wrapping
The specification does not set a line length. Git does not wrap for you either. Many teams wrap the body at 72 columns, because git log indents the message and terminals are often 80 columns wide. Wrapped body lines are harmless. Wrapped footer lines are different, as the next section shows.
Writing a body from the command line
Each -m option in git commit becomes its own paragraph, with a blank line between paragraphs. You can build a full message without opening an editor:
git commit \
-m "feat(parser): add support for array literals" \
-m "The parser now accepts [1, 2, 3] syntax and produces an ArrayNode." \
-m "Refs: #482"The first -m is the description. The second becomes the body. The third becomes the footer block. For longer messages the editor is easier. In the editor, lines starting with # are treated as comments and removed, so do not start a body line with #.
Footers
A footer is a line of the form token: value. It looks like a Git trailer, and the specification borrows the Git trailer convention on purpose.
Footer syntax
- A footer block starts one blank line after the body (or after the description if there is no body).
- Each footer is a token, then a separator, then a value.
- The separator is either
:(colon and space) or#(space and hash). - The token uses
-in place of spaces, soReviewed-byis valid andReviewed byis not. - The one exception is
BREAKING CHANGE, which is allowed to contain a space. - A value can span several lines. Parsing of that value ends when the next valid
token: valueortoken #valuepair appears.
| Footer | Separator used | What it does |
|---|---|---|
| `Refs: #482` | `: ` | Links the commit to an issue |
| `Closes #482` | ` #` | Same idea, in the hash-separator form |
| `Reviewed-by: Dana Ortiz` | `: ` | Records who reviewed the change |
| `Co-authored-by: Sam Lee <[email protected]>` | `: ` | Credits another author (GitHub reads this) |
| `BREAKING CHANGE: clients must call /v2/users` | `: ` | Flags an incompatible change |
Which footers exist
Only BREAKING CHANGE has a meaning defined by the specification. Every other footer is a team convention. Platforms often attach their own behavior to some of them. For example, GitHub closes an issue when a merged commit contains Closes #123 or Fixes #123. Choose a small set of footers, write it down, and use the same spellings every time.
Case rules
The specification says the units of a commit message are case-insensitive, with one exception. BREAKING CHANGE must be uppercase. breaking change: ... is not a breaking change footer. The hyphenated synonym BREAKING-CHANGE is also valid. Because it has no space, Git's own trailer tools handle it more naturally.
Multi-line footer values
A footer value can run over several lines:
feat(api)!: remove the deprecated /v1/users endpoint
BREAKING CHANGE: clients must call /v2/users instead.
The response shape is unchanged, but pagination now uses cursors
rather than page numbers.The second and third lines belong to the footer because neither one looks like a new token: value pair. This is also where a trap lives. A continuation line such as Note: this affects pagination would be read as a new footer called Note, ending the breaking change value early. Avoid a word followed by : at the start of a continuation line.
Reading footers with Git
Because footers follow the trailer convention, Git can parse them. git interpret-trailers extracts them from a message:
git log -1 --format=%B | git interpret-trailers --parseThe command prints only the trailer lines of the last commit. You can also ask git log for a specific trailer:
git log --format='%h %s%n refs: %(trailers:key=Refs,valueonly)' -5Git recognizes trailers only in the last paragraph of the message. If you put a footer in the middle of the body, tools will not see it. This matches the specification: footers come last.
Putting each kind of information in the right place
Choose where a fact goes by who needs it and when.
| Information | Where it goes | Why |
|---|---|---|
| A one-line summary of the change | Description | Shown in `git log --oneline` and changelogs |
| Why the change was needed | Body | Humans read it when they run `git blame` or `git show` |
| Issue numbers | Footer | Tools can parse them |
| Incompatible behavior change | `!` and a `BREAKING CHANGE` footer | Tools bump the major version from it |
| Reviewers and co-authors | Footers | Parseable and consistent |
For a breaking change, the footer text is what readers see in the changelog. Write it as an instruction to the person upgrading: what to change and what to use instead. Compare BREAKING CHANGE: endpoint removed with BREAKING CHANGE: clients must call /v2/users instead. The second one tells the reader what to do.
Common mistakes
- No blank line before the body or footers. Without it, the text is part of the description line or the previous block. Tools may not detect the footer, and a breaking change can go unnoticed.
- Wrapping a footer in the wrong place. A wrapped line that starts with
word:looks like a new footer. - A lowercase
breaking change. It is not recognized. - Spaces in custom tokens.
Reviewed by: Danais not a footer. UseReviewed-by:. - Putting the real explanation in the pull request only. If the repository is hosted elsewhere later, the explanation is lost. Commit messages travel with the repository.
- Repeating the diff in the body. "Changed line 42 from 10 to 20" adds nothing. Say why 20 is right.
Checking the body and footers
A basic commit-msg hook that only matches the first line, like the one earlier in this tutorial, does not check the body or footers. A malformed footer passes silently. A linter such as @commitlint/config-conventional includes rules for the layout, for example that the body and footer must be preceded by a blank line, and that line lengths do not exceed a limit. The exact rules and limits depend on the version of the shared config, so read the config you install. You can also change them in commitlint.config.js.
To lint the message of the last commit:
npx commitlint --from HEAD~1 --to HEADRun this once with a deliberately broken message, with no blank line between description and body. Seeing which rule fires teaches you more than reading the rule list.
Exercises
Exercise
This message is supposed to flag a breaking change, but a release tool does not bump the major version. Find two problems. feat(api): drop XML responses breaking change: clients must request JSON. The default format is now JSON.
Show answer
First, there is no blank line between the description and the footer, so the footer is not in its own block. Second, breaking change is lowercase, and the specification requires BREAKING CHANGE (or BREAKING-CHANGE) in uppercase. The ! marker after the scope would also have signaled the break. A corrected message is: feat(api)!: drop XML responses, a blank line, then BREAKING CHANGE: clients must request JSON.
Exercise
Write the git commit command that creates a message with the description "fix(cache): evict entries when memory is low", a one-sentence body of your choice, and the footer "Fixes: #910", using only -m options.
Show answer
git commit -m "fix(cache): evict entries when memory is low" -m "The cache grew without a limit under load, so it now removes the oldest entries once memory use passes the configured threshold." -m "Fixes: #910". Each -m is a separate paragraph, so the three parts are separated by blank lines.
Exercise
Why does git interpret-trailers --parse miss a Refs: #12 line placed between two body paragraphs?
Show answer
Git reads trailers only from the last paragraph of the message. A footer in the middle of the body is just body text. Footers must come last, after a blank line.