闽公网安备 35020302035485号
<type>[optional scope]: <description> [optional body] [optional footer(s)]译文:
<类型>[可选 范围]: <描述> [可选 正文] [可选 脚注]提交说明包含了下面的结构化元素,以向类库使用者表明其意图:
feat: allow provided config object to extend other configs BREAKING CHANGE: `extends` key in config file is now used for extending other config files包含了 ! 字符以提醒注意破坏性变更的提交说明
feat!: send an email to the customer when a product is shipped包含了范围和破坏性变更 ! 的提交说明
feat(api)!: send an email to the customer when a product is shipped包含了 ! 和 BREAKING CHANGE 脚注的提交说明
chore!: drop support for Node 6 BREAKING CHANGE: use JavaScript features not available in Node 6.不包含正文的提交说明
docs: correct spelling of CHANGELOG包含范围的提交说明
feat(lang): add polish language包含多行正文和多行脚注的提交说明
fix: prevent racing of requests Introduce a request id and a reference to latest request. Dismiss incoming responses other than from latest request. Remove timeouts which were used to mitigate the racing issue but are obsolete now. Reviewed-by: Z Refs: #123type 类型概览
| 值 | 描述 |
|---|---|
| feat | 新增一个功能 |
| fix | 修复一个Bug |
| docs | 文档变更 |
| style | 代码格式(不影响功能,例如空格、分号等格式修正) |
| refactor | 代码重构 |
| perf | 改善性能 |
| test | 测试 |
| build | 变更项目构建或外部依赖(例如scopes: webpack、gulp、npm等) |
| ci | 更改持续集成软件的配置文件和package中的scripts命令,例如scopes: Travis, Circle等 |
| chore | 变更构建流程或辅助工具 |
| revert | 代码回退 |
pnpm install -g commitizen pnpm install -g cz-conventional-changelog随后在电脑用户根目录穿件.czrc文件,不然使用的时候会进入命令行(笔者的系统为Ubuntu20.04)
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
随后使用commitizen生成符合AngularJS规范的提交说明commitizen init cz-conventional-changelog --save --save-exact随后你就可以使用以下命令获得中规中距的commit信息了。
git cz第二步:客制化自动提交信息
备注:cz-customizable是Commitizen的一个插件,可以帮助开发者自定义符合Angular Commit Message Conventions的提交信息格式和内容。
拜托,人又不是机器!别那么死板。和代码打交道最重要的事情就是懂得如何苦中作乐,在遇到挑战和困难时,优秀的人能够采取积极的心态,并且能够寻找解决问题的方式和方法。
npm install cz-customizable --save-dev2. 添加以下配置到package.json中
"config": {
"commitizen": {
"path": "node_modules/cz-customizable"
}
}
3.项目根目录下创建.cz-config.js文件来自定义提示├── CHANGELOG.md ├── commitlint.config.js ├── index.html ├── node_modules ├── package.json ├── pnpm-lock.yaml ├── public ├── README.md ├── src ├── tsconfig.json ├── tsconfig.node.json ├── vite.config.ts └── .cz-config.js // 创建以下是我的一些参考配置
module.exports = {
// 可选类型
types: [
{
value: ':sparkles: feat',
name: '✨ feat: 新功能'
},
{
value: ':bug: fix',
name: '🐛 fix: 修复'
},
{
value: ':memo: docs',
name: '📝 docs: 文档变更'
},
{
value: ':lipstick: style',
name: '💄 style: 代码格式(不影响代码运行的变动)'
},
{
value: ':recycle: refactor',
name: '♻️ refactor: 重构 (既不增加feature, 也不是修复bug)'
},
{
value: ':zap: perf',
name: '⚡️ perf: 性能优化'
},
{
value: ':white_check_mark: test',
name: '✅ test: 增加测试'
},
{
value: ':wrench: chore',
name: '🔧 chore: 构建过程或辅助工具的变动'
},
{
value: ':rewind: revert',
name: '⏪ revert: 回退'
},
{
value: ':rocket: build',
name: '🚀 build: 打包'
}
],
// 步骤
messages: {
type: '请选择提交的类型:',
customScope: '情输入修改的范围(可选)',
subject: '请简要描述提交(必填)',
body: '请输入详细描述(可选)',
footer: '请输入要关闭的issus(可选)',
confirmCommit: '确认要使用以上信息提交?(y/n)'
},
// 默认长度72
subjectLimit: 72
};
此时再次运行 git cz时就可以看到? 请选择提交的类型: (Use arrow keys) ❯ ✨ feat: 新功能 🐛 fix: 修复 📝 docs: 文档变更 💄 style: 代码格式(不影响代码运行的变动) ♻️ refactor: 重构 (既不增加feature, 也不是修复bug) ⚡️ perf: 性能优化 ✅ test: 增加测试第三部:增加对自动生成 commit 信息的校验
npm i @commitlint/config-conventional @commitlint/cli -D2.在根目录创建commitlint.config.js文件,配置commitlint
module.exports = {
extends: ['@commitlint/config-conventional']
}
若您使用cz-customizable了则需要使用以下配置方案npm install commitlint-config-cz --save-dev然后加入commitlint校验规则配置:
module.exports = {
extends: [
'cz'
]
};