使用Commitizen标准化规范git commit
Commitizen: 自动生成提交说明的工具
安装(建议全局)
npm install -g commitizen
npm install -g conventional-changelog
npm install -g conventional-changelog-cli
检查是否安装成功
npm ls -g -depth=0
如上 表示全局安装成功
设置Angular commit格式规范:
commitizen init cz-conventional-changelog --save --save-exact
进入项目目录,若无package.json,需初始化
npm init --yes
打开package.json,添加commitizen配置(path: 全局安装时"cz-conventional-changelog"即可,若局部安装,则为"./node_modules/cz-conventional-changelog"
)
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
在项目目录执行以下命令生成CHANGELOG.md文件:
conventional-changelog -p angular -i CHANGELOG.md -s
接下来,在要使用git commit -m命令的时候,换成git cz回车就可以啦
git add .
git cz
执行git cz后,会出现如下内容:
? Select the type of change that you're committing: (Use arrow keys)
? feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
refactor: A code change that neither fixes a bug nor adds a feature
perf: A code change that improves performance
test: Adding missing tests or correcting existing tests
选择其中一个你要提交的类型:
- feat:新的功能
- fix:修复bug
- docs:文档
- style: 代码格式(不会影响现有代码的运行的改动)
- refactor:重构(非增加新功能、非修复Bug)
- test:增加用于测试的代码(console、调试、本地写死数据等)
- chore:项目构建过程或相关辅助工具的改动
例如feat:
? Select the type of change that you're committing: feat: A new feature
? What is the scope of this change (e.g. component or file name): (press enter to skip) 增加git提交信息的详情
?Write a short, imperative tense description of the change (max 80 chars):
1.增加配置git提交信息的详情 2.去除无用代码
? Are there any breaking changes? No
? Does this change affect any open issues? No
? What is the scope of this change (e.g. component or file name): (press enter to skip):描述下本次改动的影响范围
?Write a short, imperative tense description of the change (max 80 chars): 简短描述这次改动
? Provide a longer description of the change: (press enter to skip) 详细描述本次改动
? Are there any breaking changes? 是否存在破坏性的改动y/n
? Does this change affect any open issues?(y/n) 本次改动是否会造成或关闭一些问题?如果是修复Bug,或完善需求,可以附上issue链接
最后执行git push 就能在仓库查看到提交的信息啦