Conventional Commits is a small set of rules for commit messages. Each message says what kind of change it is (a feature, a fix, a breaking change), so the history is easy to scan, and tools can generate changelogs and version numbers from it.
Structure
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]For example:
feat: add dark mode togglefix(nav): close menu after selecting a linkchore(prettier): switch tabs to spacesThe usual style for the description is the imperative mood (“add”, not “added”), lowercase, with no full stop. It should finish the sentence “this commit will…”.
Types
The spec only defines feat and fix. The rest come from the widely used Angular convention:
feat: a new featurefix: a bug fixdocs: documentation onlystyle: formatting that doesn’t change behaviour (whitespace, semicolons)refactor: a code change that neither fixes a bug nor adds a feature, e.g. renaming a functionperf: a performance improvementtest: adding or updating testsbuild: the build system or dependencies, e.g. adding a packageci: CI configuration and scriptschore: maintenance that users won’t see, e.g..gitignoreor.prettierrcrevert: reverts an earlier commit
The scope is optional and names the part of the codebase that changed: fix(auth):, feat(api):.
Body and footers
Use the body to explain why the change was made when the description alone isn’t enough. Footers come after a blank line, in Token: value form:
fix(api): retry requests after a timeout
The upstream service drops connections under load,so a single failed request was surfacing as an error.
Refs: #42Breaking changes
A commit with a
BREAKING CHANGE:footer, or a!after the type/scope, introduces a breaking API change (correlating withMAJORin Semantic Versioning). A breaking change can be part of a commit of any type.
feat(api)!: rename `getUsers` to `getUsersList`
BREAKING CHANGE: `getUsers` has been removed.How it maps to versions
| Commit | Version bump |
|---|---|
fix |
PATCH |
feat |
MINOR |
! or BREAKING CHANGE: |
MAJOR |
| anything else | none |
Resources
- Conventional Commits 1.0.0
- commitlint: checks commit messages against the convention, e.g. in a Git hook