git commit 规范及 changelog

使用插件standard-versionconventional-changelog生成 changelog 文档的方法。git

具体步骤以下:
1. 安装插件

在 package.json 文件中补充添加以下内容:github

"scripts": {
   "commit": "git-cz",
   "release": "standard-version",
   "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
   "eslint": "eslint --fix --format codeframe 'src/**.js'",
   "log": "conventional-changelog"
 },
 "devDependencies": {
    "@commitlint/cli": "^8.3.5",
    "@commitlint/config-angular": "^8.3.4",
    "@commitlint/config-conventional": "^8.2.0",
    "cz-conventional-changelog": "^3.1.0",
    "husky": "^3.1.0",
    "lint-staged": "^10.1.1",
    "standard-version": "^7.0.1"
 },
 "husky": {
    "hooks": {
      "pre-commit": "lint-staged",
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
 },
  "commitlint": {
    "extends": [
      "@commitlint/config-conventional"
    ]
 },
  "lint-staged": {
    "src/**.js": [
      "eslint --fix"
    ]
 }

而后 npm run install安装插件。web

连接:npm

2. 相关指令说明:
  • 使用 conventional-changelog 标准提交
npm run commit
  • 自动生成版本号(版本号默认加 0.0.1)并修改 changelog 文件
npm run release
  • 生成并更新 changelog 文档
npm run changelog
  • eslint 代码检查
npm run eslint
  • log 在终端打印 changelog 内容
npm run log

若是想知道更多的指令,能够在终端输入: standard-version --helpconventional-changelog --helpjson

目前使用最广的是基于 Angular 约定提交,用于说明 commit 的类别,只容许使用下面 7 个标识:ide

feat:新功能(feature)svg

fix:修补 bug工具

docs:文档(documentation)测试

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

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

test:增长测试

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

若是 type 为 feat 和 fix,则该 commit 将确定出如今 Change log 之中。其余状况(docs、chore、style、refactor、test)能够本身定义。

angular 规范连接

生成changelog文档如图:
在这里插入图片描述