使用
「cz-git」 需要 Node 版本 >=v12.20
项目中使用
只需要简单的三个步骤:
TIP
全局安装 commitizen
,如此一来可以快速使用 cz
或 git cz
命令进行启动。
sh
npm install -g commitizen
npm install -g commitizen
- 下载依赖sh
npm install -D cz-git
npm install -D cz-git
shyarn add -D cz-git
yarn add -D cz-git
shpnpm install -D cz-git
pnpm install -D cz-git
- 修改
package.json
添加config
指定使用的适配器json{ "scripts": { }, "config": { "commitizen": { "path": "node_modules/cz-git" } } }
{ "scripts": { }, "config": { "commitizen": { "path": "node_modules/cz-git" } } }
- (可选,使用默认) 添加自定义配置
👇 有两种配置方式
- (推荐) cz-git 与 commitlint 进行联动给予校验信息,所以可以编写于 commitlint 配置文件之中。
例如: (⇒ 配置模板)
js// .commitlintrc.js /** @type {import('cz-git').UserConfig} */ module.exports = { rule: { ... }, prompt: { useEmoji: true //option... } }
// .commitlintrc.js /** @type {import('cz-git').UserConfig} */ module.exports = { rule: { ... }, prompt: { useEmoji: true //option... } }
- 在
package.json
下 config.commitizen 下添加自定义配置,但过量的配置项会导致 package.json 臃肿,适合简单自定义。例如:
json{ "scripts": { "commit": "git-cz" }, "config": { "commitizen": { "path": "node_modules/cz-git", "useEmoji": true } } }
{ "scripts": { "commit": "git-cz" }, "config": { "commitizen": { "path": "node_modules/cz-git", "useEmoji": true } } }
- (推荐) cz-git 与 commitlint 进行联动给予校验信息,所以可以编写于 commitlint 配置文件之中。
全局使用
全局安装的好处在于:在任何项目下都可以利用
cz
或git cz
命令启动命令行工具,生成标准化 commit message
只需要简单的三个步骤:
- 下载全局依赖sh
npm install -g cz-git commitizen
npm install -g cz-git commitizen
- 全局配置适配器类型sh
echo '{ "path": "cz-git", "$schema": "https://raw.githubusercontent.com/Zhengqbbb/cz-git/refs/tags/1.11.2/docs/public/schema/cz-git.json" }' > ~/.czrc
echo '{ "path": "cz-git", "$schema": "https://raw.githubusercontent.com/Zhengqbbb/cz-git/refs/tags/1.11.2/docs/public/schema/cz-git.json" }' > ~/.czrc
- (可选,使用默认) 添加自定义配置
👇 有两种配置方式
- 编辑
~/.czrc
文件以JSON
格式添加配置, 例如:
json{ "path": "cz-git", "useEmoji": true }
{ "path": "cz-git", "useEmoji": true }
- 与 commitlint 配合,在
$HOME
路径下创建配置文件
(↓ 配置模板)
- 编辑