commit 之 Angular 规范
1、commit 基本类型:
feat
: 新功能(feature)fix
: 修改bugdocs
: 文档(documentation)style
: 格式(不影响代码运行的变动)refactor
: 重构(即不是新增功能,也不是修改bug的代码变动)test
: 增加测试chore
: 构建过程或辅助工具的变动
2、commit 基本结构:
<type>(<scope>): <subject>
// 空一行
<body>
// 空一行
<footer>
type
commit 的类型。scope
用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。subject
commit目的的简短描述,不多于50字。body
是本次提交详细的描述,格式是与 type 空一行,与下面的 footer 也空一行。footer
一般描述不兼容情况和关闭的 issues。
3、安装 commitizen 简化提交方式
nmp install -g commitizen
安装完成后便可以额使用 git cz
替代 git commit
4、安装工具检测提交是否合乎规范
- install commitlint
npm init
npm install --save-dev @commitlint/{cli,config-conventional}
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
- install husky
npm install --save-dev husky
package.json 文件里面插入:
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
注意:
- 少量多次提交,方便 review,一次修改比较大,应对相关修改分类,分多次提交。
- 修改 bug 可以将 jira 相关的问题的代号关联。