Git Commitizen 简单集成须知

集成动机

为了规范团队 git commit 的提交记录

便于清晰化 跟踪 及 关联某个具体功能

项目中引进了 commitizen/cz-cli

此工具可为开发者提供可选择的 commit 提交,提交的 type 分为以下几种:

- feat : 新 feature ,新增一个新的功能点
- fix : bug fix , 修复某个已知 bug
- docs: 文档变更(比如项目中的 开发规范文档)
- style: 格式变更 (不影响功能代码,如一个 空格,代码对齐 等修复)
- refactor: 代码重构,重构了某个功能 或者 view
- perf: 性能优化, 优化了某个页面流畅度等
- test: 测试
- build: 变更项目构建 或者 依赖
- ci : 更新持续集成的 命令 / 配置文件 
- revert: 代码回滚


集成步骤

1.通过 npm 安装 cz 工具

npm install -g commitizen

2.安装适配器

commitizen init cz-conventional-changelog --save --save-exact

此步骤若项目中之前存在适配器,可以用 --force 覆盖

如果不报错,即可在项目中 使用 git cz 来 代替 git commit


报错须知

1.当前 用户目录下不存在 package.json ,须手动创建 package.json

2. 如果第一次安装npm ,则可以在安装 npm 后,执行 npm init,系统自动生成 package.json

3. 执行 git cz 找不到 changelog,路径报错

Could not resolve /node_modules/cz-conventional-changelog. Cannot find module '/node_modules/cz-conventional-changelog'
Require stack:
- /usr/local/lib/node_modules/commitizen/dist/commitizen/adapter.js
- /usr/local/lib/node_modules/commitizen/dist/commitizen.js
- /usr/local/lib/node_modules/commitizen/dist/cli/git-cz.js
- /usr/local/lib/node_modules/commitizen/bin/git-cz.js
- /usr/local/lib/node_modules/commitizen/bin/git-cz

打开 package.json, 修改如下,去除 ./node_modules/

  "config": {
    "commitizen": {
     - "path": "./node_modules/cz-conventional-changelog"
     + "path": "cz-conventional-changelog"
    }
  }


简单使用

git add . 之后使用 git cz ,如下图:

$ git cz
[email protected], [email protected]

? Select the type of change that you're committing: (Use arrow keys)
❯ feat:     A new feature
  fix:      A bug fix
  docs:     Documentation only changes
  style:    Changes that do not affect the meaning of the code (white-space, for
matting, missing semi-colons, etc)
  refactor: A code change that neither fixes a bug nor adds a feature
  perf:     A code change that improves performance
(Move up and down to reveal more choices)

选择某个 type 后,中间的 组建名 / 文件名 这一步 可回车跳过

最后输入此次提交文案 ,之后 git push 即可

你可能感兴趣的:(Git Commitizen 简单集成须知)