目前项目提交信息写的比较随意 只能看到开发人员每次备注的信息 为了后期协作以及处理Bug时会更加方便 引入commit规范,每次commit时,commitlint会用在git的hook回调中,最简单的就是和 husky一起使用
commit message: <type>: <subject> (注意冒号后面有空格)
type:
feat
:新功能(feature)fix
:修补bugdocs
:文档(documentation)style
: 格式(不影响代码运行的变动)refactor
:重构(即不是新增功能,也不是修改bug的代码变动)test
:增加测试chore
:构建过程或辅助工具的变动- upgrade: 第三方库升级
- revert:回滚
subject:
subject是 commit 目的的简短描述
实现步骤
1 安装commitlint库
https://www.npmjs.com/package/@commitlint/config-conventional
cnpm install @commitlint/cli @commitlint/config-conventional
2 在commitlint.config.js(在项目根目录创建)制定提交message规范,其中rules可以自定义添加一些规则
https://commitlint.js.org/#/reference-rules
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', [
"feat", "fix", "docs", "style", "refactor", "test", "chore", "revert" , "upgrade","revert","build"
]],
'subject-full-stop': [0, 'never'],
'subject-case': [0, 'never']
}
}
3 结合git hook检验commit message 这里使用husky,保证提交前触发commitlint https://github.com/typicode/husky
cnpm install husky --save-dev
package.json里添加配置(与dependencies并列)
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
eg: git commit -m "feat: 增加****列表"