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..2]:0禁用规则。因为1它将被视为2错误警告。

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

:用于此规则的值。

参考链接: commitlint官网

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,164评论 0 10
  • 前提: 安装webpack、webpack-cli 一、首先先让出来一个页面有内容 先添加.gitignore,将...
    codingQi阅读 5,319评论 0 0
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 7,951评论 0 0
  • This project was bootstrapped with Create React App. Belo...
    unspecx阅读 10,597评论 0 2
  • 这两天滴滴事件再次刷屏,但这次所有朋友圈的口径几乎完全呈现一边倒的趋势,那就是,数落、谴责甚至是唾骂滴滴平...
    kent6688阅读 1,300评论 2 1