Validates a git commit message against The seven rules:
- Separate subject from body with a blank line
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line
- Wrap the body at 72 characters
- Use the body to explain what and why vs. how
The bolded rules 1-6 are checked. The remaining rule 7 is not detectable programmatically.
Rule 5 (Imperative mood) is heuristically checked using a blacklist of terms, but might give false negatives in some cases. The blacklist is based on this git hook.
The title of rule 2 says 50 characters but the body clarifies 72 is the hard limit.
A husky hook is provided for ease of use.
Inspired by the quality Bash implementation.
Installation through husky
Install husky
and sevenrules
:
npm install husky @romeovs/sevenrules --save-dev
# or
yarn add husky @romeovs/sevenrules --dev
Hook the validator to commit-msg
in your package.json
:
{
"husky": {
"hooks": {
"commit-msg": "sevenrules"
}
}
}
Enjoy your clean commit log!
npm install --global husky @romeovs/sevenrules
# or
yarn global add husky @romeovs/sevenrules
In the git repository you want to use sevenrules
, add it to your commit-msg
hook manually:
echo 'sevenrules "$@"' >> .git/hooks/commit-msg
chmod u+x .git/hooks/commit-msg
Enjoy your clean commit log!
$ git commit -m "Updated README.md"
Your commit message breaks one of the seven rules of commit messages
Rule 5: Use the imperative mood in the subject line
For more info on the seven rules, see https://chris.beams.io/posts/git-commit
commit-msg hook failed (add --no-verify to bypass)
Respect agency. Follow the Code of Conduct.
Anybody caught using this work without our permission, will be mighty good friends of ourn, cause we don't give a dern. Study it. Hack it. Publish it, even without naming the source. We made it, that's all we wanted to do.
Released under the Severn license, an MIT derivative without the notice requirement. Contributor signatures available in the contributors repository.
NO rights reserved.