Sub topic 9
Conventional Commits: encoding the version bump in commit messages
This chapter assumes you know semantic versioning (MAJOR.MINOR.PATCH), can write basic git commits, and can read a GitHub Actions workflow. Here you learn a commit message format that tools can read to pick the next version number.
The problem it solves
Under semantic versioning, someone must decide whether a release is a patch, a minor or a major bump. Doing this by hand is slow and inconsistent. People forget that a change broke compatibility, or they argue about the number at release time.
Conventional Commits moves that decision into each commit message. A tool can then read the commits since the last tag and calculate the next version without human judgment at release time.
The message format
A conventional commit message has a type, an optional scope, an optional !, a colon and a short description:
type(scope): description
optional body
optional footerThe scope names the area of the code, such as fix(parser): handle empty input. It does not affect the version.
How types map to version bumps
The commit type tells a tool which part of the version to raise.
| Commit | Meaning | Version bump |
|---|---|---|
| `fix:` | A bug fix | PATCH |
| `feat:` | A new feature | MINOR |
| `feat!:` or `fix!:` | A breaking change | MAJOR |
| Footer `BREAKING CHANGE:` | A breaking change on any type | MAJOR |
| `docs:`, `chore:`, `test:`, `refactor:` | No change to released behavior | Normally no release |
When a release contains several commits, the highest bump wins. One feat: and five fix: commits give a MINOR bump.
Here are some examples:
fix: handle empty config file
feat: add --dry-run option
feat!: drop support for Node 16
docs: clarify install stepsWith these four commits since v1.4.2, the feat! commit forces a MAJOR bump, so the next version is v2.0.0. The docs commit does not normally trigger a release on its own.
A breaking change can also be marked in the footer. This is useful when you want to explain the break:
feat: replace the config file format
BREAKING CHANGE: config.ini is no longer read. Use config.toml instead.From commits to a release
The flow below shows where the commit messages are used.
A tool such as release-please, covered in a later chapter, does this calculation for you. It reads the commits on main, picks the next version and opens a release pull request. Conventional Commits is the input that makes that automation possible.
Common errors
- A wrong type. A
feat:commit for what is really a bug fix inflates the version and misleads readers. Choose the type from the effect on users, not the size of the diff. - A missing colon or space.
fix handle crashandfix:handle crashdo not match the format. Tools usually skip such commits, so they do not appear in the changelog and do not count toward the bump. - Unmarked breaking changes. If you remove an option but write
refactor:, the tool releases a patch or nothing. Users then upgrade and break. Always add!or aBREAKING CHANGE:footer. - Squash merges that lose the message. If your repository squash-merges pull requests, the pull request title often becomes the commit message on
main. In that case the title must follow the format, not the individual commits inside the branch.
Conventional Commits and generated notes
GitHub's generated release notes, covered earlier, group changes by pull request label. Conventional Commits groups them by commit type. These are two different sources for the same kind of summary. Pick one per repository. Mixing them produces notes that disagree with the version number.
Exercise
A repository is at v2.3.1. Since that tag, these commits were merged to main: fix: correct timezone offset, docs: update README, feat(api): add pagination, chore: bump linter. What is the next version, and what would change it to v3.0.0?
Show answer
The next version is v2.4.0, because the highest change is the feat commit, which is a MINOR bump. The fix adds nothing more, and docs and chore do not normally trigger a bump. It would become v3.0.0 if any commit were marked breaking, for example feat(api)!: add pagination or a commit with a BREAKING CHANGE: footer.
Exercise
A team squash-merges pull requests. A branch has three commits that all follow Conventional Commits, but the pull request is titled "Update stuff". Why might the release tool ignore this change?
Show answer
With squash merging, the pull request title becomes the single commit message on main. "Update stuff" has no type and no colon, so the tool cannot classify it and skips it. The fix is to rename the title, for example to fix: correct timezone offset.