Sub topic 3
Choosing a type: feat, fix, and the rest
This chapter assumes you can write commits with git commit, you know the shape of a conventional commit (type, optional scope, description), and you have a basic idea of Semantic Versioning. Here you learn how to pick the right type for a change.
Why the type matters
The type is the first word of the message. Tools and people read it before anything else. It tells them what kind of change the commit makes. Two types carry meaning in the specification, and the rest are conventions.
featadds a new feature. It maps to a MINOR version bump.fixrepairs a bug. It maps to a PATCH version bump.
The specification only requires these two. Other types are allowed, and many teams use the set from the Angular convention, which @commitlint/config-conventional also uses.
The common types
| Type | Use it for | Example |
|---|---|---|
| `feat` | A new capability for users of the code | `feat: add CSV export` |
| `fix` | A bug fix | `fix: prevent crash when the config file is empty` |
| `docs` | Documentation only | `docs: explain the retry settings` |
| `style` | Formatting that does not change behavior | `style: apply formatter to utils` |
| `refactor` | Restructuring that neither fixes a bug nor adds a feature | `refactor: split the parser into modules` |
| `perf` | A change that improves performance | `perf: cache compiled patterns` |
| `test` | Adding or correcting tests | `test: cover empty input in the parser` |
| `build` | Build system or dependency changes | `build: upgrade the bundler` |
| `ci` | CI configuration and scripts | `ci: run tests on pull requests` |
| `chore` | Maintenance that fits nowhere else | `chore: update .gitignore` |
| `revert` | Undoing an earlier commit | `revert: remove the new cache layer` |
Type names are case-insensitive in the specification, but pick lowercase and keep it consistent. Many linters reject mixed case.
Deciding which type fits
Ask what changed for the people who use the code, not which files you touched.
- Does the commit add behavior that users can now do and could not before? Use
feat. - Does it correct behavior that was wrong? Use
fix. - Does it change only docs, tests, formatting, build files, or CI? Use the matching type.
- Does it change internals while behavior stays the same? Use
refactor, orperfif the point is speed.
Cases that cause confusion
A bug fix that also touches tests. Use fix. The tests support the fix, so they belong in the same commit. Do not split them just to use a test type.
A dependency bump. Use build for build tooling and ordinary dependency updates. If the update fixes a bug that your users hit, fix is accurate, because it changes what they receive.
A change that does two things. Prefer two commits. If you cannot split them, use the type with the larger effect. A commit that adds a feature and fixes a bug should be feat, since that is the bump that matters.
Formatting versus refactoring. style means whitespace, semicolons, and similar edits that do not alter the code's meaning. Renaming functions or moving code is refactor.
Type versus release impact. Only feat, fix, and breaking changes affect the version number by default. A perf commit does not raise the version in most tools unless you configure it. If a change should ship in a release, check that its type triggers one.
Looking at history by type
A consistent prefix makes plain git log a filter:
git log --oneline --grep='^feat'
git log --oneline --grep='^fix'The ^ anchors the match to the start of the message. Without it you would also match commits that merely mention "fix" later in the text.
Exercise
You rename three internal functions and move them to a new file. No behavior changes, and no tests change. Which type fits, and does it trigger a release by default?
Show answer
Use refactor. The code is restructured but behavior is the same, so it is not a feat or fix. By default refactor does not trigger a version bump, because only feat, fix, and breaking changes do.
Exercise
A commit adds a new --json flag to a command line tool and also fixes a typo in the README. Which single type would you choose if you could not split it, and why?
Show answer
feat. It has the larger effect, since it adds a capability and maps to a MINOR bump. The README fix is minor. Splitting it into a feat commit and a docs commit would be better.