1.说明
上一章我们使用husky
和commitlint
,限制了我们的Git
的Commit
的消息格式。这样我们每一次提交消息虽然规范了,但是也更麻烦了。为了不去手敲哪些麻烦的规范,这次安装一个插件,让这个插件通过命令行询问的方式为我们提交规范的commit
消息。
参考链接:
2.安装
# 安装
yarn add commitizen --dev
# 初始化适配器(告诉它,我们要什么样的commit消息格式)
npx commitizen init cz-conventional-changelog --yarn --dev --exact
在VbenAdmin
中我没有看到第二步操作的输出的配置代码,很纳闷。
3.测试
yarn cz
# 执行命令工程
# 开始回答问题!
# 选择一个你这次commit的变更类型(上下选择,回车确定),后面的括号式该类型变更的描述,比如build的,你拿去翻译翻译就知道是咋回事了
? Select the type of change that you're committing: build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
# 描述这次变更的范围,这里我打了一个'scope',等会看结果就知道是啥了。
? What is the scope of this change (e.g. component or file name): (press enter to skip) scope
# 短标题,最长86个字符,前面的括号是当前字符数
? Write a short, imperative tense description of the change (max 86 chars):
(15) 我们安装了commitizen
# 长描述
? Provide a longer description of the change: (press enter to skip)
a longer description,一个很长的描述
# 这次有突破性的变更吗?随便选吧
? Are there any breaking changes? No
# 这个次变更有对应哪个(issues)么?随便整吧
? Does this change affect any open issues? No
# ...之前配置的husky检查
�🔍 Finding changed files since git revision 406a766.
�🎯 Found 0 changed files.
✅ Everything is awesome!
On branch master
Your branch is up to date with 'origin/master'.
# husky检查报错啦。当然啦,我们没有暂存文件,直接commit的。
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: package.json
modified: yarn.lock
no changes added to commit (use "git add" and/or "git commit -a")
git exited with error code 1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
最重结果如下:
build(scope): 我们安装了commitizen
,
# ...
�🔍 Finding changed files since git revision 406a766.
�🎯 Found 1 changed file.
✅ Everything is awesome!
[master ebe2b2c] build(scope): 我们安装了commitizen
2 files changed, 970 insertions(+), 12 deletions(-)
Done in 39.38s.
# 推送出去
git push -u origin master
打开我们的远程仓库,还是看的到其他信息的。

上一章
第十九章-使用husky规范代码提交
下一章
第二十一章-使用conventional-changelog-cli生成变更记录