使用Commitizen规范git提交

更新时间:2023-05-16 19:57:57 阅读: 评论:0

使⽤Commitizen规范git提交
提交规则
1.1 commit message format(信息域)
赎罪 atonement
commit message⼀般分为三个部分Header,Body 和 Footer
<type>(<scope>): <subject>
// 空⼀⾏
<body>
// 空⼀⾏
春望的翻译<footer>
其中,Header 是必需的,Body 和 Footer 可以省略
1.2 HEAD
fable
type⽤于说明 commit 的类别,使⽤下列标识
feat:    新功能
fix:      修复
docs:    ⽂档变更
style:    代码格式(不影响代码运⾏的变动)
refactor: 重构(既不是增加feature,也不是修复bug)
perf:    性能优化
test:    增加测试
chore:    构建过程或辅助⼯具的变动
revert:  回退
build:    打包
scope ⽤来说明本次Commit影响的范围,即简要说明修改会涉及的部分,⽐如数据层、控制层、视图层等,
subject comment所在的位置,这次提交的简短描述
1.3 Body 是对本次 commit 的详细描述,可以分成多⾏
1.4 Footer 部分只⽤于两种情况
不兼容变动
如果当前代码与上⼀个版本不兼容,则 Footer 部分以BREAKING CHANGE开头,后⾯是对变动的描述、以及变动理由和迁移⽅法关闭 Issue
如果当前 commit 针对某个issue,那么可以在 Footer 部分关闭这个 issue (可依次关闭过个issue Clos #123, #245, #992)
1.5 Revert
还有⼀种特殊情况,如果当前 commit ⽤于撤销以前的 commit,则必须以revert:开头,后⾯跟着被撤销 Commit 的 Header
revert: type(scope):  some comment
花痕
This reverts commit bfe307ce57d87677c6c473c228e6c2ed8b81dcec.
Body部分的格式是固定的,必须写成This reverts commit <hash>.,其中的hash是被撤销 commit 的 HSHA 标识符。
如果当前 commit 与被撤销的 commit,在同⼀个发布(relea)⾥⾯,那么它们都不会出现在 Change log ⾥⾯。如果两者在不同的发布,那么当前 commit,会出现在 Change log 的Reverts⼩标题下⾯
安装Commitizen⼯具
前提需要安装node
1.全局安装⽅案
1.1 全局安装commitizen node模块
npm install -g commitizen
1.2 初始化commitizen的适配器cz-customizable
vitalizing
cz-customizable可以⾃定义提交提⽰信息
npm install -g cz-customizable
1.3 .czrc 在 home ⽬录中创建⼀个⽂件,并 path 引⽤⾸选的全局安装的 commitizen 适配器{"path":"cz-customizable"}
1.4 在package.json中添加代码
...
"config": {
"commitizen": {
"path": "cz-customizable"
}
}
1.5 1.2到1.4的步骤也可以使⽤命令⾏实现
commitizen init cz-customizable --save-dev --save-exact
上⾯的命令为你做三件事。
安装cz-customizable适配器npm模块
节省了devDependencies包的依赖关系
添加了 itizen 关键你的根源 package.json 如下所⽰:
...
"config": {
2013年12月英语六级成绩查询
"commitizen": {
"path": "cz-customizable"
}
}
1.6 添加cz-customizable的配置⽂件.cz-config.js到与.git同级⽂件夹
'u strict';
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 follows
messages: {
type: '请选择提交类型:',
// scope: '请输⼊⽂件修改范围(可选):',
// ud if allowCustomScopes is true
customScope: '请输⼊修改范围(可选):',
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默认是72
subjectLimit: 72
};
1.7 现在 cd 进⼊任何 git 存储库并使⽤ git cz ⽽不是git commit。 你会发现 commitizen 提⽰。
提⽰:可以使⽤所有 git commit options 带 git cz,例如:git cz -a。
2.项⽬安装⽅案(⾮全局)
NPM版本⾼于5.2
2.1 使⽤命令⾏npm install --save-dev commitizen
雅思培训哪家好
六月英文缩写2.2 使⽤命令⾏npx commitizen init cz-customizable --save-dev --save-exact
2.3 使⽤命令⾏npx git-cz
或者添加npm脚本
...
"scripts": {
幽姿不入少年场
"commit": "npx git-cz"
}
2.4 添加cz-customizable的配置⽂件.cz-config.js到与.git同级⽂件夹
2.5 使⽤ git cz

本文发布于:2023-05-16 19:57:57,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/111040.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:提交   安装   代码   变动   描述   部分   影响   跟着
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图