commitlint checks if your commit message meets the conventional commit format
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
- commitlint
Download binary from releases and add it to your PATH
go install github.com/conventionalcommit/commitlint@latest- Enable for a single git repository,
cdto repository directory
commitlint init- Enable globally for all git repositories
commitlint init --global- to customize hooks destination pass
--hookspathwith desired location
commitlint init --hookspath /path/to/hooks
commitlint init --global --hookspath /path/to/hooks- run
commitlint hookto create.commitlint/hookscontaining git hooks- pass
--hookspathor-pto customize the hooks output path
- pass
- To enable in single repo
- run
git config core.hooksPath /path/to/.commitlint/hooks
- run
- To enable globally
- run
git config --global core.hooksPath /path/to/.commitlint/hooks
- run
- To remove hooks from a single repository
commitlint remove- To remove hooks globally
commitlint remove --globalBoth commands ask for confirmation before unsetting core.hooksPath in git config. Hook files are left intact.
- Valid commit message
echo "feat: good commit message" | commitlint lint
# ✔ commit message- Invalid commit message
echo "fear: do not fear for commit message" | commitlint lint
# ❌ type-enum: type 'fear' is not allowed, you can use one of [build chore ci docs feat fix merge perf refactor revert style test]-
To create a config file, run
commitlint config create, this will create.commitlint.yamlwith only the enabled rules and their settings (compact format) -
To create a config file with all rules and settings written out (including disabled ones), run
commitlint config create --all -
To validate a config file, run
commitlint config check /path/to/conf.yaml
To lint a message, you can use any one of the following
- run
commitlint lint --message=file - run
echo "message" | commitlint lint - run
commitlint lint < file
commitlint lint follows below order for config and message
- config file passed to
--configcommand-line argument COMMITLINT_CONFIGenv variable- config file in current directory or git repo root in the below order
- .commitlint.yml
- .commitlint.yaml
- commitlint.yml
- commitlint.yaml
- default config
stdinpipe stream- commit message file passed to
--messagecommand-line argument .git/COMMIT_EDITMSGin current directory
- To create hook files, run
commitlint hook- pass
--hookspathor-pto customize the hooks output directory - pass
--replaceor-rto overwrite existing hook files
- pass
To prints useful information for debugging commitlint
run commitlint debug
min-version: v0.11.0
formatter: default
rules:
- header-min-length
- header-max-length
- body-max-line-length
- footer-max-line-length
- type-enum
severity:
default: error
rules: {}
settings:
body-max-line-length:
argument: 100
flags: {}
footer-max-line-length:
argument: 100
flags: {}
header-max-length:
argument: 72
flags: {}
header-min-length:
argument: 10
flags: {}
type-enum:
argument:
- feat
- fix
- docs
- style
- refactor
- perf
- test
- build
- ci
- chore
- revert
flags: {}
disable-default-ignores: false
ignores: []Commonly used commit types from Conventional Commit Types
| Type | Description |
|---|---|
| feat | A new feature |
| fix | A bug fix |
| docs | Documentation only changes |
| style | Changes that do not affect the meaning of the code (white-space, formatting etc) |
| refactor | A code change that neither fixes a bug nor adds a feature |
| perf | A code change that improves performance |
| test | Adding missing tests or correcting existing tests |
| build | Changes that affect the build system or external dependencies |
| ci | Changes to our CI configuration files and scripts |
| chore | Other changes that don't modify src or test files |
| revert | Reverts a previous commit |
commitlint automatically skips linting for commit messages generated by git (merges, reverts, fixups, etc.). If the first line of a commit message matches any ignore pattern, linting is skipped entirely.
The following patterns are enabled by default
(source: config/default.go):
| Pattern | Matches |
|---|---|
^Merge pull request #\d+ |
GitHub pull request merges |
^Merge .+ into .+ |
Generic merge (X into Y) |
^Merge branch '.+' |
git merge branch |
^Merge tag '.+' |
git merge tag |
^Merge remote-tracking branch '.+' |
git merge remote-tracking branch |
^Merged .+ (in|into) .+ |
Azure DevOps / Bitbucket merged |
^Merged PR #?\d+ |
Azure DevOps pull request |
^(R|r)evert |
git revert |
^(R|r)eapply |
git reapply |
^(amend|fixup|squash)! |
git commit --fixup/--squash/--amend |
^Automatic merge |
Automatic merges |
^Auto-merged .+ into .+ |
Auto-merged branches |
^Initial commit$ |
Initial commit (exact match) |
Add your own patterns in the config file under ignores:. User-defined patterns are
additive, they are checked alongside the built-in defaults.
ignores:
- "^WIP "
- "^TICKET-\\d+"If you want only your custom patterns (no built-in defaults), set disable-default-ignores: true:
disable-default-ignores: true
ignores:
- "^WIP "The list of available lint rules
| name | argument | flags | description |
|---|---|---|---|
| header-min-length | int | n/a | checks the min length of header (first line) |
| header-max-length | int | n/a | checks the max length of header (first line) |
| body-max-line-length | int | n/a | checks the max length of each line in body |
| footer-max-line-length | int | n/a | checks the max length of each line in footer |
| type-enum | []string | n/a | restrict type to given list of string |
| scope-enum | []string | allow-empty: bool | restrict scope to given list of string |
| footer-enum | []string | n/a | restrict footer token to given list of string |
| type-min-length | int | n/a | checks the min length of type |
| type-max-length | int | n/a | checks the max length of type |
| scope-min-length | int | n/a | checks the min length of scope |
| scope-max-length | int | n/a | checks the max length of scope |
| description-min-length | int | n/a | checks the min length of description |
| description-max-length | int | n/a | checks the max length of description |
| body-min-length | int | n/a | checks the min length of body |
| body-max-length | int | n/a | checks the max length of body |
| footer-min-length | int | n/a | checks the min length of footer |
| footer-max-length | int | n/a | checks the max length of footer |
| type-charset | string | n/a | restricts type to given charset |
| scope-charset | string | n/a | restricts scope to given charset |
| footer-type-enum | []{token, types, values} | n/a | enforces footer notes for given type |
- default
commitlint
→ input: "fear: do not fear for ..."
Errors:
❌ type-enum: type 'fear' is not allowed, you can use one of [build chore ci docs feat fix perf refactor revert style test]
Total 1 errors, 0 warnings, 0 other severities
- JSON
{"input":"fear: do not fear for commit message","issues":[{"description":"type 'fear' is not allowed, you can use one of [build chore ci docs feat fix perf refactor revert style test]","name":"type-enum","severity":"error"}]}-
How to have custom config for each repository?
Place
.commitlint.yamlfile in repo root directory. linter follows config precedence.To create a sample config, run
commitlint config create(orcommitlint config create --allto include all available settings) -
How can I skip lint check for a commit?
use
--no-verifyflag withgit commitwhich skips commit hooks -
How does commitlint handle merge / revert commits?
commitlint ships with built-in ignore patterns that automatically skip linting for merge commits, reverts, fixups, squashes, and other git-generated messages. You can add your own patterns with the
ignoresconfig key, or disable the defaults withdisable-default-ignores: true. -
Can I use the old
versionconfig key?Yes. The
versionkey is still accepted for backward compatibility, but new config files should usemin-versioninstead.
All packages are licensed under MIT License