A pre-commit
hook to check commit messages for
Conventional Commits formatting.
Make sure pre-commit
is installed.
Create a blank configuration file at the root of your repo, if needed:
touch .pre-commit-config.yaml
Add a new repo entry to your configuration file:
repos:
# - repo: ...
- repo: https://github.com/compilerla/conventional-pre-commit
rev: <git sha or tag>
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: [] # optional: list of Conventional Commits types to allow
Install the pre-commit
script:
pre-commit install --hook-type commit-msg
Make a (normal) commit ❌:
$ git commit -m "add a new feature"
[INFO] Initializing environment for ....
Conventional Commit......................................................Failed
- hook id: conventional-pre-commit
- duration: 0.07s
- exit code: 1
[Commit message] add a new feature
Your commit message does not follow Conventional Commits formatting
https://www.conventionalcommits.org/
Conventional Commits start with one of the below types, followed by a colon,
followed by the commit message:
build chore ci docs feat fix perf refactor revert style test
Example commit message adding a feature:
feat: implement new API
Example commit message fixing an issue:
fix: remove infinite loop
Optionally, include a scope in parentheses after the type for more context:
fix(account): remove infinite loop
Make a (conventional) commit ✔️:
$ git commit -m "feat: add a new feature"
[INFO] Initializing environment for ....
Conventional Commit......................................................Passed
- hook id: conventional-pre-commit
- duration: 0.05s
Versioning generally follows Semantic Versioning.
In addition to the strict version tag, we also maintain a "latest" tag for each
major version, e.g. v1
always points to the latest v1.x.x
tag.
Inspired by matthorgan's pre-commit-conventional-commits
.