Skip to content
导航栏

使用

「cz-git」 需要 Node 版本 >=v12.20

项目中使用

只需要简单的三个步骤:

TIP

全局安装 commitizen,如此一来可以快速使用 czgit cz 命令进行启动。

sh
npm install -g commitizen
npm install -g commitizen
  1. 下载依赖
    sh
    npm install -D cz-git
    npm install -D cz-git
    sh
    yarn add -D cz-git
    yarn add -D cz-git
    sh
    pnpm install -D cz-git
    pnpm install -D cz-git
  2. 修改 package.json 添加 config 指定使用的适配器
    json
    {
      "scripts": {
    
      },
      "config": {
        "commitizen": {
          "path": "node_modules/cz-git"
        }
      }
    }
    {
      "scripts": {
    
      },
      "config": {
        "commitizen": {
          "path": "node_modules/cz-git"
        }
      }
    }
  3. (可选,使用默认) 添加自定义配置

    👇 有两种配置方式

    1. (推荐) 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...
      }
    }
    1. 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
        }
      }
    }

全局使用

全局安装的好处在于:在任何项目下都可以利用 czgit cz 命令启动命令行工具,生成标准化 commit message

只需要简单的三个步骤:

  1. 下载全局依赖
    sh
    npm install -g cz-git commitizen
    npm install -g cz-git commitizen
  2. 全局配置适配器类型
    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
  3. (可选,使用默认) 添加自定义配置

    👇 有两种配置方式

    1. 编辑 ~/.czrc 文件以 JSON 格式添加配置, 例如:
    json
    {
      "path": "cz-git",
      "useEmoji": true
    }
    {
      "path": "cz-git",
      "useEmoji": true
    }
    1. commitlint 配合,在 $HOME 路径下创建配置文件
      (↓ 配置模板)

我只是尽力将工具做得更好,如果可以的话欢迎给一个 star ⭐