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规范

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 采用 Angular 的 commit 规范。 不写 commit message 不允许提交代码,具体的规范格式...
    前端大飞阅读 12,061评论 1 6
  • 前言 Git 每次提交代码,都要写 Commit message(提交说明),否则就不允许提交。但是,一般来说,c...
    guanguans阅读 126,818评论 1 63
  • 使用angular + commitizen + cz-conventional-changelog 来规范git...
    喜相逢v5阅读 5,876评论 0 4
  • git提交估计也快上万次了,每次不知道怎么写好,今天在网上找到一套规范然后加上常用的一些,总结出来一套 Git c...
    Jinbeen阅读 8,505评论 0 1
  • 又到襄县去,我和暖暖等得太无聊,决定随便逛逛。 路口的那户人家门前,有两棵鸡冠花,顶上三朵鸡冠花毛...
    暖暖的微笑倾城阅读 2,586评论 0 1

友情链接更多精彩内容