Sub topic 8
How commits map to MAJOR, MINOR, and PATCH
This chapter assumes you know Semantic Versioning (MAJOR.MINOR.PATCH) and can write the type, scope, description, body, and footers of a conventional commit. It shows how the type and the breaking-change markers in each commit decide the next version number. It also covers where the spec stays silent and how to compute the bump yourself.
The three rules in the specification
Semantic Versioning ties a version number to the kind of change a release contains:
- A PATCH release contains backward-compatible bug fixes.
- A MINOR release adds backward-compatible functionality.
- A MAJOR release contains incompatible changes to the public API.
Conventional Commits 1.0.0 states how commits relate to those three levels:
| Commit | Version bump |
|---|---|
| Type `fix` | PATCH |
| Type `feat` | MINOR |
| Any type with `!` after the type or scope, or with a `BREAKING CHANGE:` footer | MAJOR |
The breaking-change rule applies to every type, not only feat and fix. A refactor!: commit or a chore: commit with a BREAKING CHANGE: footer both produce a MAJOR bump. The commit type describes the kind of work. The breaking marker says whether the public contract changed. The two are independent.
feat(api)!: remove the deprecated /v1/users endpoint
BREAKING CHANGE: clients must call /v2/users instead.This commit is a feat, which alone would mean MINOR. The ! and the footer raise it to MAJOR.
The highest bump wins
A release usually contains many commits. The version changes once per release, and the largest bump among its commits decides it:
- Any breaking commit produces MAJOR.
- Otherwise, any
featproduces MINOR. - Otherwise, any
fixproduces PATCH. - Otherwise, there is nothing to release, by default.
Ten fix commits and one feat commit produce one MINOR bump, not ten PATCH bumps. Bumps never accumulate. Starting from 1.4.2:
| Commits since last release | Next version |
|---|---|
| `fix: a`, `fix: b`, `fix: c` | `1.4.3` |
| `fix: a`, `feat: b` | `1.5.0` |
| `fix: a`, `feat: b`, `feat(api)!: c` | `2.0.0` |
| `docs: a`, `chore: b` | no release |
Lower numbers reset when a higher number rises. A MINOR bump sets PATCH to 0, and a MAJOR bump sets both MINOR and PATCH to 0.
What the other types do
The spec allows types besides feat and fix, such as docs, style, refactor, perf, test, build, ci, and chore. These come from the Angular convention and from @commitlint/config-conventional, and the spec does not require them. The spec says they have no implicit effect on Semantic Versioning, unless the commit includes a breaking change.
Release tools are free to add rules of their own. For example, some presets of semantic-release treat perf as a PATCH. Others release nothing for it. If you rely on such a rule, read your tool's configuration instead of assuming. Treat any non-spec mapping as a project decision that you should write down.
This matters when you pick a type. A change that fixes a bug in code users run is a fix, even if the change is small. A change to a test file or a CI script is not a fix, even if it repairs something broken. It is test or ci, because users of the package see no difference. Using fix for internal repairs triggers releases that contain nothing new for users.
Choosing between feat, fix, and a breaking marker
The mapping makes the choice of type a statement about the public API. These questions help:
- Does a caller of the public API see new behavior they can opt into? Use
feat. - Does the code now do what it was documented to do, where before it did not? Use
fix. - Can an existing caller's code or configuration stop working after upgrading? Mark the commit as breaking, whatever its type.
Bug fixes can break callers. If callers depended on the buggy behavior, a fix that removes it may be a breaking change. Semantic Versioning counts compatibility, not the intent of the commit. Decide which guarantee your project documents, and mark commits accordingly.
A single commit has one type, so a commit that adds a feature and fixes a bug should usually be split in two. If you cannot split it, use the type with the larger effect, here feat. The spec says that if a commit fits more than one type, you should split it into several commits where possible.
Computing the bump yourself
Release tools do this work for you, but a short script shows the rules plainly and lets you check what a branch would release. The script below reads commit messages separated by NUL characters, and it takes the current version as its argument.
# next_version.py
import re
import sys
HEADER = re.compile(r"^(?P<type>[A-Za-z]+)(\([^)]+\))?(?P<bang>!)?: .+")
BREAKING = re.compile(r"^BREAKING[ -]CHANGE: .+", re.MULTILINE)
ORDER = {"patch": 1, "minor": 2, "major": 3}
def level(message):
lines = message.strip().splitlines()
if not lines:
return None
match = HEADER.match(lines[0])
if not match:
return None
if match.group("bang") or BREAKING.search(message):
return "major"
commit_type = match.group("type").lower()
if commit_type == "feat":
return "minor"
if commit_type == "fix":
return "patch"
return None
def next_version(current, messages):
major, minor, patch = (int(part) for part in current.split("."))
levels = [lvl for lvl in map(level, messages) if lvl]
if not levels:
return current
top = max(levels, key=ORDER.get)
if top == "major":
return f"{major + 1}.0.0"
if top == "minor":
return f"{major}.{minor + 1}.0"
return f"{major}.{minor}.{patch + 1}"
if __name__ == "__main__":
messages = sys.stdin.read().split("\0")
print(next_version(sys.argv[1], messages))Test it without a repository by piping in messages:
printf 'fix: handle empty input\0docs: update readme\0' | python3 next_version.py 1.4.2
printf 'fix: a\0feat(parser): add array literals\0' | python3 next_version.py 1.4.2
printf 'fix: a\0feat(api)!: remove /v1/users\0' | python3 next_version.py 1.4.2The output is 1.4.3, then 1.5.0, then 2.0.0. To use it on real history, list the messages since the last tag. The %x00 placeholder makes Git print a NUL after each message:
git log v1.4.2..HEAD --format=%B%x00 | python3 next_version.py 1.4.2The script is a sketch. The footer pattern matches BREAKING CHANGE: at the start of any line, which is slightly looser than the spec's footer grammar. It also skips merge commits and messages that do not follow the format, because level returns None for them. Real tools parse the footer section more strictly.
Versions below 1.0.0
Semantic Versioning treats 0.y.z as initial development, where anything may change at any time. The spec does not say how breaking commits should bump a 0.y.z version, so tools differ:
- Some tools apply the normal rules, so a breaking change in
0.3.1produces1.0.0. - Some tools shift everything down one level, so a breaking change produces
0.4.0and afeatproduces0.3.2. - Many tools let you choose, using an option or a setting.
Check which behavior your tool uses before the first release. Moving from 0.x to 1.0.0 is a decision about declaring a stable API. It should not happen by accident because one commit had a !.
Edge cases
- Wrong type means wrong version. If someone writes
chore:for what is really a user-visible feature, no MINOR release happens. If someone writesfeat:for a refactor, users get a version bump with nothing new. The mapping is only as accurate as the commit types. - A missing marker hides a breaking change. If a commit breaks callers but lacks
!or the footer, the release will be too small. Callers who trust the version number will upgrade and break. Review the breaking marker with the same care as the type. - Commits that don't follow the format are ignored. Most tools skip a message such as
Update stuffwhen computing the bump. A squashed merge with a non-conforming message can hide a real feature or breaking change. - Squash merges change which message counts. With squash merges, the only commit that reaches the main branch is the squashed one. Its message, not the individual commits on the branch, sets the bump. The pull-request chapter covers this.
- Reverts follow the normal rules. The spec leaves revert handling open. A
reverttype commit has no implicit bump in the spec, so tools differ. A revert of afeatthat was already released may need a manual decision. - Pre-release tags are separate. A tag like
2.0.0-rc.1follows the Semantic Versioning pre-release rules. Conventional Commits does not define how commits map onto it. Your release tool decides.
Putting it together
The mapping is short: fix is PATCH, feat is MINOR, and any breaking marker is MAJOR. What makes it work is consistency. Types have to match the change, breaking markers have to be present when callers are affected, and the main branch has to receive conforming messages. When those hold, the version number becomes a trustworthy summary of what changed.
Exercise
Your last release is 2.3.1. Since then the main branch received these commits: docs: fix typo in install guide, fix(cli): exit with code 1 on invalid flag, refactor(core)!: rename Config.load to Config.read, and feat: add --json output. What is the next version, and which commit decides it?
Show answer
The next version is 3.0.0. The refactor(core)!: commit is breaking, so it sets a MAJOR bump, which outranks the MINOR from feat and the PATCH from fix. The docs commit has no effect. The MAJOR bump resets MINOR and PATCH to 0.
Exercise
A commit has the header chore: update parser dependency and a footer BREAKING CHANGE: the minimum supported Node version is now 20. Does it cause a release, and of what size?
Show answer
Yes, it causes a MAJOR release. A BREAKING CHANGE: footer applies to any type, so the chore type does not prevent a MAJOR bump. The type alone would produce no release.
Exercise
A developer fixes a bug in a test helper that is not part of the published package and writes fix: correct test helper. What problem can this cause, and which type is better?
Show answer
The fix type maps to PATCH, so release tooling will publish a new patch version that contains no change for users. The type test is better, since it has no implicit version effect and describes the change accurately.