I. Introduction
-
1. Generally we use the
git
submission code, and the common commands aregit add .
git commit -m '这是什么代码'
git push origin master
-
2. Using the traditional way to
git
submit the code is the following result
-
3. There are several disadvantages of this method
- I don’t know what I submitted as time goes by
- No classification management of submitted code
- Inconvenient to find a certain modification
-
4. In response to these problems, the most commonly used in the industry is the specification used by the Angular team; when git commit, a vim editor pops up to edit a submission information of the template type. The main format is as follows:
<type>(<scope>):<subject> <BlLANK_LINE> <?body> <BLANK_LINE> <?footer>
- The first line is required: mainly [Submission Type (Scope of Impact): Brief Description]
body
For detailed description, I have not used it much- The footer is destructively changed or closed a
issues
-
5. The format of the code submitted after using the specification
2. How to use
-
1. Installation package
npm i -D commitlint-config-cz cz-customizable npm i -D @commitlint/cli @commitlint/config-conventional npm i -D commitizen commitlint-config-cz
-
2. Create a
.cz-config.js
file in the root directory of the projectmodule.exports = { types: [ { value: 'init', name: 'init: 初始提交' }, { value: 'feat', name: 'feat: 增加新功能' }, { value: 'fix', name: 'fix: 修复bug' }, { value: 'improvement', name: 'improvement: 对当前特性的改进' }, { value: 'docs', name: 'docs:修改文档' }, { value: 'style', name: 'style: 样式修改不影响逻辑' }, { value: 'refactor', name: 'refactor: 代码重构(既不修复bug也不添加特性的代码更改)' }, { value: 'perf', name: 'perf: 代码重构(改进性能的代码更改)' }, { value: 'test', name: 'test: 添加缺失的测试或修改现有的测试' }, { value: 'build', name: 'build: 影响构建系统或外部依赖项的更改(例如作用域:gulp、broccoli、npm)' }, { value: 'ci', name: 'ci: 对CI配置文件和脚本的更改(示例范围:Travis、Circle、BrowserStack、SauceLabs)' }, { value: 'chore', name: 'chore: 不修改src或测试文件的其他更改' }, { value: 'revert', name: 'revert: 版本回退' }, { value: 'ui', name: 'ui: 更新UI' }, { value: 'release', name: 'release: 发布' }, { value: 'deploy', name: 'deploy: 部署' }, { value: 'chore', name: 'chore: 更改配置文件' }, { value: 'add', name: 'add: 添加依赖' }, { value: 'minus', name: 'minus: 版本回退' }, { value: 'del', name: 'del: 删除代码/文件' } ], scopes: [], messages: { type: '选择更改类型:\n', scope: '更改的范围:\n', // 如果allowcustomscopes为true,则使用 customScope: '此更改的范围(例如组件或文件名称)', subject: '简短描述:', body: '详细描述. 使用"|"换行:', breaking: '变化文件的列表:', footer: '关闭的issues列表. E.g.: #31, #34:', confirmCommit: '确认提交?' }, allowCustomScopes: true, allowBreakingChanges: ["feat", "fix"] };
-
3. Create in the root directory of the project
commitlint.config.js
module.exports = { extends: [ '@commitlint/config-conventional', 'cz' ], rules: { // Header 'header-max-length': [2, 'always', 200], // <type>枚举 'type-enum': [2, 'always', [ 'init', 'feat', 'fix', 'improvement', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert', 'ui', 'release', 'deploy', 'chore', 'add', 'minus', 'del', ]], // <type> 不能为空 'type-empty': [2, 'never'], // <type> 格式 小写 'type-case': [2, 'always', 'lower-case'], // <scope> 不能为空 'scope-empty': [2, 'never'], // <scope> 格式 小写 'scope-case': [2, 'always', 'lower-case'], // <subject> 不能为空 'subject-empty': [2, 'never'], // <subject> 以.为结束标志 'subject-full-stop': [2, 'never', '.'], // <subject> 格式 // 可选值 // 'lower-case' 小写 lowercase // 'upper-case' 大写 UPPERCASE // 'camel-case' 小驼峰 camelCase // 'kebab-case' 短横线 kebab-case // 'pascal-case' 大驼峰 PascalCase // 'sentence-case' 首字母大写 Sentence case // 'snake-case' 下划线 snake_case // 'start-case' 所有首字母大写 start-case 'subject-case': [2, 'never', []], // <body> 以空行开头 'body-leading-blank': [1, 'always'], // <footer> 以空行开头 'footer-leading-blank': [1, 'always'] } }
-
4.
package.json
Add in{ ... "config": { "commitizen": { "path": "node_modules/cz-customizable" } } }
-
5. Combine
git hook
to checkcommit message
to prevent you from submitting when you submit code that does not meet the specificationsnpm install husky -D
-
6. The hook function
package.json
configuredgit hook
in{ ... "husky": { "hooks": { "commit-msg": "commitlint -e $GIT_PARAMS" } }, }
-
7.
package.json
Configure the command directly in the modecommit
{ "scripts": { "commit": "./node_modules/cz-customizable/standalone.js" }, }
-
8. How to submit code
git add . npm run commit git push origin master ```![在这里插入图片描述](https://img-blog.csdnimg.cn/20200107144931441.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2t1YW5nc2hwMTI4,size_16,color_FFFFFF,t_70)