Install pre-git for handling Git hooks and commitizen for helping format the commit messages
npm install pre-git commitizen cz-conventional-changelog --save-dev
The package cz-conventional-changelog
will validate the message using
AngularJS-style guideline: <type>(<scope>): <subject>
Set the commit message hook command to validate the message using AngularJS-style
guidelines in package.json
"config": {
"pre-git": {
"commit-msg": "validate-commit-msg"
}
}
Configure the npm run commit
command
"scripts": {
"commit": "git-cz"
},
"czConfig": {
"path": "node_modules/cz-conventional-changelog"
}
That is it. Now instead of running the git commit
just use npm run commit
to commit the
staged files. Answer simple questions and get useful and valid commit messages.
You can always skip commit message validation (and pre-commit hook too) by using -n
or --no-verify
command line argument to git commit
Additional info:
I added validator and helper to pre-git module, thus all you need to do is
to install npm install pre-git --save-dev
- the hooks and everything will be
configured automatically. Then you should use git add . && npm run commit
command
to commit code.