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
cz-cli@4.2.1, cz-conventional-changelog@3.2.0

? 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 即可

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容