最近接手了旧项目,包含原生小程序,原则上是不允许添加额外包,所以找了一个commit提交规范的插件,感觉还挺好用推荐给大家,当然如果是多人团队项目还是建议大家用commitzen +husky + lint-staged来约束团队成员。
安装完后重启编辑器,在修改完文件后,会发现侧边栏出现一个铅笔图标
我们点击它会出现一个新界面:
我们点击Edit as form随便选选写点东西
点击save之后,侧边的git模块就会生成我们的选项
点击提交即可,你也可以复制到其他commit图形化工具上使用,比如sourceTree(windows版本的没有commit模板)。
默认的配置不包含表情,贴出我的配置,可以引入修改使用,大家也可以添加自己的选项,完整的 gitmoji 大家可以自行查看添加。
{ "$schema": "https://bendera.github.io/vscode-commit-message-editor/schemas/config-v1.schema.json", "configVersion": "1", "staticTemplate": [ "✨feat: 新功能", "", "简短描述", "", "关闭的issues列表或解决的提测bug" ], "dynamicTemplate": [ "{type}{scope}: {subject}", "", "{body}", "", "{breaking_change}", "", "{footer}" ], "tokens": [ { "label": "Type", "name": "type", "type": "enum", "options": [ { "label": "✨feat: 新功能", "description": "新功能" }, { "label": "🐛fix: bug修复", "description": "bug修复" }, { "label": "🔨refactor: 代码重构", "description": "不包括 bug 修复、功能新增" }, { "label": "🎨style: 样式修改", "description": "不影响代码含义的更改(空白、格式、缺少分号等)" }, { "label": "📝docs: 修改文档", "description": "修改文档" }, { "label": "🚀perf: 性能优化", "description": "性能优化" }, { "label": "✅test: 添加缺失的测试或纠正现有测试", "description": "添加缺失的测试或纠正现有测试" }, { "label": "🔧build: 构建流程、外部依赖变更", "description": "如升级 npm 包、修改 脚手架 配置等" }, { "label": "⚙️ci: 对CI配置文件和脚本的更改", "description": "对CI配置文件和脚本的更改" }, { "label": "👌chore: 对构建过程或辅助工具和库的更改", "description": "不影响源文件、测试用例" }, { "label": "⏪revert: 版本回退", "description": "版本回退" }, { "label": "🚧wip: 开发中", "description": "未完成的工作" }, { "label": "🔥del: 删除代码/文件", "description": "删除代码/文件" }, { "label": "🎉init: 初始提交", "description": "初始提交(初次创建项目)" }, { "label": "📚complex: 复合型提交", "description": "代码提交涉及以上多个内容" } ], "description": "选择更改类型" }, { "label": "Scope", "name": "scope", "description": "更改的范围", "type": "text", "multiline": false, "prefix": "(", "suffix": ")" }, { "label": "Subject", "name": "subject", "description": "简短描述", "type": "text", "multiline": false }, { "label": "Body", "name": "body", "description": "详细描述", "type": "text", "multiline": true, "lines": 5, "maxLines": 10 }, { "label": "Breaking change", "name": "breaking_change", "description": "Breaking Changes列表", "type": "boolean", "value": "BREAKING CHANGE: ", "default": false }, { "label": "Footer", "name": "footer", "description": "关闭的issues列表. E.g.: #31, #34", "type": "text", "multiline": true } ]}
可以先点击导出配置文件,然后修改配置文件后再次导入,并保存至工作区,这样一份属于自己的commit配置就生成好了。
Edit as Text和Edit as form的区别就是是否在一行显示,用form编辑的正文只能点击查看,text适合简短或者不想写太多commit使用,大家可以根据自己的需要进行选择。