git commit 规范

之前使用的validate-commit-msgghooks已经不在支持使用了,带来了更加标准化的 commitlint

起步

安装

husky 类似之前的ghooks

npm install -g @commitlint/cli @commitlint/config-conventional
npm install --save-dev husky

配置

echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js

husky 配置package.json

{
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }  
  }
}

验证

如果执行之后,和下面一样就是ok的

git commit -m "foo: this will fail"
husky > npm run -s commitmsg

⧗   input: foo: this will fail
✖   type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]
✖   found 1 problems, 0 warnings

husky > commit-msg hook failed (add --no-verify to bypass)

git commit -m "chore: lint on commitmsg"
husky > npm run -s commitmsg

⧗   input: chore: lint on commitmsg
✔   found 0 problems, 0 warnings

生成changelog

npm install -g conventional-changelog-cli
conventional-changelog -p angular -i CHANGELOG.md -s

参考文章

阮大大的commit规范
conventionalcommits规范

你可能感兴趣的:(git commit 规范)