git commit 提交规范 & 规范校验

Install commitlint

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

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

或者配置可以在被定义.commitlintrc.js,.commitlintrc.json或者.commitlintrc.yml文件或commitlint在字段package.json

例如在package.json中加入
"commitlint": {
  "extends": [ "@commitlint/config-conventional" ],
  "rules": {
    "type-enum": [ 2, "always", [ "feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert" ] ],
    "type-case": [ 2, "always", [ "lower-case" ] ],
    "type-empty": [ 2, "never" ], "scope-empty": [ 2, "never" ],
    "scope-case": [ 2, "always", [ "lower-case", "upper-case", "camel-case", "kebab-case", "pascal-case", "sentence-case", "snake-case", "start-case" ] ],
    "subject-case": [ 2, "always", [ "lower-case", "upper-case", "camel-case", "kebab-case", "pascal-case", "sentence-case", "snake-case", "start-case" ] ],
    "subject-empty": [ 2, "never" ],
    "subject-full-stop": [ 2, "never" ],
    "header-max-length": [ 2, "always", 72 ]
  }
}

Install husky


npm install --save-dev husky

This allows us to add git hooks directly into our package.json via the husky.hooks field.

// package.json

"husky": {

        "hooks": {

            "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"

        } 

  }

commit规范


Commit message格式

type(scope?): subject 

注意冒号后面有空格。

type

用于说明 commit 的类别,只允许使用下面7个标识。

feat:新功能(feature)

fix:修补bug

docs:文档(documentation)

style: 格式(不影响代码运行的变动)

refactor:重构(即不是新增功能,也不是修改bug的代码变动)

test:增加测试

chore:构建过程或辅助工具的变动

scope[optional]

表示改动的模块或者文件或者功能

subject

提交简短的问题描述

规则


规则由名称和配置数组组成。配置数组包含:

级别 [0,1,2]:0禁用规则 1报warning 2.报error。

适用 always|never:never颠倒规则。

值:用于此规则的值。

参考链接: commitlint官网

posted @ 2019-03-29 18:03  伍声2016  阅读(1834)  评论(0编辑  收藏  举报