Sub topic 7
Flagging Breaking Changes with ! and BREAKING CHANGE
This chapter assumes you can write a basic conventional commit (type, optional scope, description), you know what MAJOR.MINOR.PATCH means in Semantic Versioning, and you are comfortable with Git on the command line.
What counts as a breaking change
A breaking change is a change that forces users of your code to modify theirs. Examples include removing an endpoint, renaming a public function, or changing what a return value means. The type of the commit does not decide this. A fix, a feat, or a refactor can all be breaking.
Conventional Commits gives you two ways to say so. Tools read these markers to decide the next version number, and people read them to know what to check before upgrading.
Marker 1: the ! before the colon
Put ! directly before the colon. If there is a scope, it goes after the closing parenthesis.
feat!: send an email to the customer when a product is shipped
feat(api)!: remove the deprecated /v1/users endpointThe ! is visible in git log --oneline, so the warning shows up even in a short listing.
Marker 2: the BREAKING CHANGE footer
Add a footer that starts with BREAKING CHANGE: in capital letters, followed by a space and a description. The footer goes after the body, separated by a blank line.
feat(api): remove the deprecated /v1/users endpoint
The v1 endpoint has been unsupported since the last release.
BREAKING CHANGE: clients must call /v2/users instead.The footer has room for migration advice. Use it to say what users must do, not only what you removed.
Using both together
You can combine the markers. The ! makes the commit stand out in one-line logs, and the footer carries the explanation.
feat(api)!: remove the deprecated /v1/users endpoint
BREAKING CHANGE: clients must call /v2/users instead.When you use ! without a footer, the description itself should explain the break. When you use the footer without !, the commit is still breaking, but a reader scanning the log will not see it.
Rules that cause errors
BREAKING CHANGEmust be uppercase.breaking change:in lowercase is not recognized by the specification as a breaking footer.- The specification also accepts
BREAKING-CHANGEas a synonym for the footer token. - The footer needs a colon and a space after the token, in the same
token: valueform as other footers. - The
!goes immediately before the colon.feat !: ...andfeat:! ...are invalid. - The footer must be separated from the body by a blank line.
Effect on versioning
A breaking change correlates with a MAJOR bump in Semantic Versioning, whatever the commit type is. A fix!: therefore produces a new major version. The next chapter covers the full mapping.
Catching a missing marker with a hook
A linter can check the format, but it cannot know whether you changed an API. That judgment is yours. A useful habit is to ask before committing: "Could someone upgrade to this commit and have working code stop working?" If yes, add a marker.
The commit-msg hook pattern from the topic accepts the ! already, through the !? part of the regular expression:
#!/bin/sh
# .git/hooks/commit-msg (must be executable)
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9._-]+\))?!?: .+'
if ! head -n 1 "$1" | grep -Eq "$pattern"; then
echo "Commit message must look like: type(scope)!: description" >&2
exit 1
fiThis hook only checks the first line. It does not verify the footer, so a malformed BREAKING CHANGE footer passes unnoticed.
Exercise
A commit has the header fix(auth): reject expired tokens and, after a blank line, the footer breaking change: sessions older than 1 hour are now invalid. Does a tool following the specification treat it as breaking? How would you fix it, and what version bump follows?
Show answer
No. The footer token is lowercase, so it is not recognized. Write BREAKING CHANGE: sessions older than 1 hour are now invalid, or change the header to fix(auth)!: reject expired tokens, or use both. Once recognized as breaking, the commit leads to a MAJOR version bump even though its type is fix.
Exercise
Write a commit message for removing the --legacy flag from a command-line tool, using the scope cli, both breaking markers, and a footer that tells users what to do.
Show answer
feat(cli)!: remove the --legacy flag BREAKING CHANGE: scripts that pass --legacy must drop the flag and use the default output format.