VSCode中Commitizen生效的关键是让git commit走cz流程,而非仅装插件;需通过专用命令Git: Commitizen Commit或绑定extension.gitCommitizen.commit快捷键(如Ctrl+Enter)触发,配置文件须为CommonJS格式的.cz-config.js或package.json中config.cz-customizable字段。

VSCode 里用 Commitizen 提交,核心不是装插件,而是让 git commit 命令实际走 cz 流程 —— 否则点“提交”按钮还是手动写 message,插件形同虚设。
为什么装了 vscode-commitizen 插件却没反应
常见现象:插件已安装、.cz-config.js 也写了,但右键 Git 提交或 Ctrl+Shift+P → “Git: Commit” 仍弹出原始输入框,不触发交互式提问。
根本原因:VS Code 默认的提交行为完全绕过 Commitizen,插件只响应特定命令(如 Git: Commitizen Commit),不劫持原生提交入口。
解决路径只有两条:
- 改用插件提供的专用命令(推荐新手):按 Ctrl+Shift+P → 输入
Git: Commitizen Commit手动触发 - 覆盖 VS Code 原生提交行为(推荐团队落地):在
.vscode/settings.json中强制重定向git.postCommitCommand
注意:"git.postCommitCommand": "commitizen" 是无效配置 —— 这个字段实际只支持内置命令(如 git.refresh),不能执行外部 CLI。真正生效的是 "git.enableSmartCommit": false + 绑定快捷键到 extension.gitCommitizen.commit 命令。
如何让 Ctrl+Enter 提交自动走 cz 流程
目标是:按下 Ctrl+Enter(或点击绿色对勾)时,直接唤起 Commitizen 交互界面,而非弹出原始输入框。
操作步骤(实测有效,VS Code 1.89+):
- 打开
keybindings.json(Ctrl+Shift+P → “Preferences: Open Keyboard Shortcuts (JSON)”) - 添加以下绑定,覆盖默认提交快捷键:
{
"key": "ctrl+enter",
"command": "extension.gitCommitizen.commit",
"when": "scmViewFocus && !inputFocus"
}
说明:
-
extension.gitCommitizen.commit是 vscode-commitizen 插件注册的真实命令 ID,不是git.commit -
when条件确保只在源代码管理面板聚焦且无输入框激活时生效,避免干扰编辑器内换行 - 无需修改
settings.json中的git.postCommitCommand,那个字段对插件无作用
cz 配置文件写在哪、怎么写才被识别
vscode-commitizen 插件按固定顺序查找配置,顺序错就回退到默认模板(英文、全字段):
- 优先读取
package.json中的config.cz-customizable字段(注意不是commitizen) - 其次找项目根目录下的
.cz-config.js(必须是 CommonJS 导出,ESM 不支持) - 最后 fallback 到内置
cz-conventional-changelog
典型 .cz-config.js 示例(中文、跳过非必要字段):
module.exports = {
types: [
{ value: 'feat', name: '✨ 新功能' },
{ value: 'fix', name: '? 修复 Bug' },
{ value: 'docs', name: '? 文档更新' },
{ value: 'refactor', name: '♻️ 代码重构' },
],
skipQuestions: ['scope', 'body', 'breaking', 'footer'],
messages: {
type: '选择本次变更类型:',
subject: '简要描述(不超过 50 字):',
}
};
关键点:
-
skipQuestions必须是字符串数组,写成['scope'],不是{ scope: true } - 如果用了
cz-customizable,插件不会读cz-conventional-changelog的配置 - 配置改完要重启 VS Code 窗口,热重载不生效
CHANGELOG.md 自动生成失败的常见卡点
生成日志本身和 VS Code 提交流程无关,依赖的是 conventional-changelog-cli 工具链,但容易因 Git 标签或历史格式中断:
- 第一次运行
npx conventional-changelog -p angular -i CHANGELOG.md -s前,必须已有带语义化版本的 Git tag(如v1.0.0),否则报No releases found - 历史提交若混有非 Conventional 格式(如
git commit -m "update"),工具会跳过它们,导致日志不全 —— 可加-r 0强制从首次提交开始扫描 - VS Code 插件不参与日志生成,必须单独配置
package.json脚本:
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
}
真正麻烦的是:一旦团队有人绕过 Commitizen 直接 git commit -m,后续所有自动化(日志、CI 分析、自动发布)都会断链 —— 没有强制 hook,仅靠流程约定,长期必然失效。











