集成动机
为了规范团队 git commit 的提交记录
便于清晰化 跟踪 及 关联某个具体功能
项目中引进了 commitizen/cz-cli
此工具可为开发者提供可选择的 commit 提交,提交的 type 分为以下几种:
1 2 3 4 5 6 7 8 9 10 | - feat : 新 feature ,新增一个新的功能点 - fix : bug fix , 修复某个已知 bug - docs: 文档变更(比如项目中的 开发规范文档) - style: 格式变更 (不影响功能代码,如一个 空格,代码对齐 等修复) - refactor: 代码重构,重构了某个功能 或者 view - perf: 性能优化, 优化了某个页面流畅度等 - test: 测试 - build: 变更项目构建 或者 依赖 - ci : 更新持续集成的 命令 / 配置文件 - revert: 代码回滚 |
集成步骤
1.通过 npm 安装 cz 工具
1 | npm install -g commitizen |
2.安装适配器
1 | commitizen init cz-conventional-changelog --save --save-exact |
此步骤若项目中之前存在适配器,可以用
如果不报错,即可在项目中 使用
报错须知
1.当前 用户目录下不存在
2. 如果第一次安装
3. 执行 git cz 找不到
1 2 3 4 5 6 7 | 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, 修改如下,去除
1 2 3 4 5 6 | "config": { "commitizen": { - "path": "./node_modules/cz-conventional-changelog" + "path": "cz-conventional-changelog" } } |
简单使用
1 2 3 4 5 6 7 8 9 10 11 12 | $ 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 后,中间的
最后输入此次提交文案 ,之后