已解决
git commit 规范及自动化
来自网友在路上 153853提问 提问时间:2023-10-08 18:55:55阅读次数: 53
最佳答案 问答题库538位专家为你答疑解惑
文章目录
- 规范描述
- header 格式
- type 必填
- scope 选填
- subject
- 项目配置
- 1. 安装
- 2. 配置文件
- 3. 自动生成 Change Log
规范描述
commit message需要包括两部分内容:header和body
- header(推荐):简要描述此次commit的改动范围/内容
- body(可选):若代码出现较大改变时填写
header 格式
header部分只有一行,包括三个字段:
<type>(<scope>):<subject>
type 必填
说明commit类型,只允许使用以下标识
breaking
:不兼容的改动,接口删除、数据库字段更新等,具体不兼容的部分用scope说明feat
:新功能(feature)fix
:修复bugperf
:优化(包括提升性能、体验)refactor
:重构(不是新增功能,也不是修改bug的代码改动)docs
:文档调整(documentation)style
:格式调整test
:测试调整(增加测试用例等)chore
:构建过程或辅助工具的变动revert
:回滚到某个版本
scope 选填
说明commit更改的文件名,多个用“,”分开
subject
commit简短描述
项目配置
1. 安装
// 全局安装
npm install commitizen -g
// 项目目录下安装
npm i commitlint --save-dev
npm i @commitlint/config-conventional --save-dev
npm i husky --save-dev
npm install commitizen --save-dev
# 用于自动生成 change log
npm i conventional-changelog-cli --save-dev
2. 配置文件
在项目目录下,新建配置文件 commitlint.config.js
module.exports = {extends: ['@commitlint/config-conventional'],rules: {// type 类型定义'type-enum': [2, 'always', ["feat", // 新功能 feature"fix", // 修复 bug"docs", // 文档注释"style", // 代码格式(不影响代码运行的变动)"refactor", // 重构(既不增加新功能,也不是修复bug)"perf", // 性能优化"test", // 增加测试"chore", // 构建过程或辅助工具的变动"revert", // 回退"build" // 打包]],// subject 大小写不做校验// 自动部署的BUILD ROBOT的commit信息大写,以作区别'subject-case': [0]}
};
在项目目录下,新建配置文件 .cz-config.js
'use strict';module.exports = {types: [{value: 'feat', name: 'feat: 新功能'},{value: 'fix', name: 'fix: 修复'},{value: 'docs', name: 'docs: 文档变更'},{value: 'style', name: 'style: 代码格式(不影响代码运行的变动)'},{value: 'refactor', name: 'refactor: 重构(既不是增加feature,也不是修复bug)'},{value: 'perf', name: 'perf: 性能优化'},{value: 'test', name: 'test: 增加测试'},{value: 'chore', name: 'chore: 构建过程或辅助工具的变动'},{value: 'revert', name: 'revert: 回退'},{value: 'build', name: 'build: 打包'}],// override the messages, defaults are as followsmessages: {type: '请选择提交类型:',// scope: '请输入文件修改范围(可选):',// used if allowCustomScopes is truecustomScope: '请输入修改范围(可选):',subject: '请简要描述提交(必填):',body: '请输入详细描述(可选,待优化去除,跳过即可):',// breaking: 'List any BREAKING CHANGES (optional):\n',footer: '请输入要关闭的issue(待优化去除,跳过即可):',confirmCommit: '确认使用以上信息提交?(y/n/e/h)'},allowCustomScopes: true,// allowBreakingChanges: ['feat', 'fix'],skipQuestions: ['body', 'footer'],// limit subject length, commitlint默认是72subjectLimit: 72
};
在package.json文件中增加相关配置
{..."scripts": {...,"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",},...,"husky": {"hooks": {"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"}},"config": {"commitizen": {"path": "./node_modules/cz-customizable"}}
}
3. 自动生成 Change Log
运行 npm run changelog
虽然只能生成简短的 commit 提交记录,但是已经提供了框架和基本 log
手动修改生成后的 log 文件即为项目 log
查看全文
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"git commit 规范及自动化":http://eshow365.cn/6-17397-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!