Skip to content

Git提交规范

方跃明 2020-01-02

Husky接管Git钩子在commit-msg时利用commitlint检查提交规范。

参考

实现

安装开发依赖

shell
yarn install -D husky
yarn install -D @commitlint/cli
yarn install -D @commitlint/config-conventional

配置package.json

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

commit规范

shell
type(scope?): subject  #scope is optional

生成CHANGELOG

安装依赖

shell
yarn install -D conventional-changelog
yarn install -D conventional-changelog-cli

package.json

json
"scripts": {
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
}

生成

shell
yarn changelog  # 在项目根目录生成CHANGELOG.md

Git钩子执行ESLint

详见规范构建教程

Git