cz-git 是一个 Commitizen 适配器,用来自定义Gitcommit信息。高度自定义、轻量级、支持 Emoji,与 Commitlint 配合使用更方便. 并且不需要单独的配置文件

https://lee-oss-1300118632.cos.ap-nanjing.myqcloud.com/obsidian/202310242310757.gif

与 Commitlint 配合使用

commitlint的配置文件使用 commitlint.config.ts 文件,获取 TypeScript 类型支持

如果不使用 cz-git的情况下,配置文件是这样的:

import type {UserConfig} from '@commitlint/types';
import {RuleConfigSeverity} from '@commitlint/types';
 
const Configuration: UserConfig = {
  extends: ['@commitlint/config-conventional'],
  parserPreset: 'conventional-changelog-atom',
  formatter: '@commitlint/format',
  rules: {
    'type-enum': [RuleConfigSeverity.Error, 'always', ['foo']],
  },
  ignores: [(commit) => commit === ''],
  defaultIgnores: true,
  helpUrl:
    'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
  prompt: {
    messages: {},
    questions: {
      type: {
        description: 'please input type:',
      },
    },
  },
};
 
module.exports = Configuration;

类型UserConfigRuleConfigServerity枚举值是从 @commitlint/type 这个单独的包中获取的。Configuration

cz-gitcommitlint的类型进行了重写,以支持 cz-gitprompt类型提示,所以这里直接从cz-git中获取类型配置和枚举值
快速开始 | cz-git

import type { UserConfig } from "cz-git";
import { RuleConfigSeverity } from "cz-git";
 
const Configuration: UserConfig = {
  extends: ['@commitlint/config-conventional'],
  parserPreset: 'conventional-changelog-atom',
  formatter: '@commitlint/format',
  rules: {
    'type-enum': [RuleConfigSeverity.Error, 'always', ['foo']],
  },
  ignores: [(commit) => commit === ''],
  defaultIgnores: true,
  helpUrl:
    'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
  prompt: {
    messages: {},
    questions: {
      type: {
        description: 'please input type:',
      },
    },
  },
};
 
module.exports = Configuration;