Sub topic 3
How Commits Map to MAJOR, MINOR, and PATCH
This chapter assumes you know basic Git commands, commit-message editing, Semantic Versioning, and terminal use.
Mapping commits to version changes
Conventional Commits gives release tools a predictable signal:
| Commit pattern | Typical version bump | Meaning |
|---|---|---|
| `fix:` | PATCH | A backward-compatible bug fix |
| `feat:` | MINOR | A backward-compatible feature |
| `BREAKING CHANGE` or `!` | MAJOR | An incompatible public change |
For example, feat(parser): support arrays usually adds a MINOR version. fix: handle empty input adds a PATCH version. feat(api)!: remove /v1/users requires a MAJOR version.
flowchart TD
A[Conventional commit] --> B{Breaking change?}
B -->|Yes| C[MAJOR]
B -->|No| D{feat type?}
D -->|Yes| E[MINOR]
D -->|No| F[PATCH]Enforcing the format
A commit-msg hook checks each message before Git creates the commit. Git passes the message-file path as $1.
#!/bin/sh
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 "Use type(scope)!: description" >&2
exit 1
fiFor shared rules, use commitlint:
npm install --save-dev @commitlint/cli @commitlint/config-conventional
npx commitlint --from HEAD~1 --to HEADRun it in the hook and in CI. Local checks give fast feedback; CI protects the repository.
Pull requests and squash merges
Teams often require the pull request title to use the same format. During a squash merge, that title becomes the final commit message. This preserves one meaningful, machine-readable entry even when a branch contains temporary commits.
Reverting commits
The specification does not define a special revert format. A revert: type is common. Add references so tools and readers can identify the reverted commits.
revert: restore the previous timeout behavior
Refs: 676104e, a215868Changelogs and releases
Changelog and release tools scan commit types, scopes, and breaking-change markers. They can group feat and fix entries, calculate the next version, and create release notes. The tools still need project-specific rules, especially for commits that should not appear publicly.
:::callout tip Use ! and a BREAKING CHANGE: footer when the compatibility impact deserves extra explanation. The marker drives automation; the footer explains the migration. :::
Common mistakes and adoption tips
- Do not label every change
fix; choose the user-visible meaning. - Keep scopes consistent, such as
api,parser, ordocs. - Describe what changed, not the ticket number alone.
- Agree on rules before enabling strict checks.
- Let developers amend messages locally, but keep CI as the final check.
Exercise
What version bump should feat(auth)!: remove password login trigger?
Show answer
A MAJOR bump, because ! marks a breaking change.