git commit规范,代码提交工具推荐

目录

一、代码提交风格

1.安装Commitizen

2.安装cz-conventional-changelog,并且初始化cz-conventional-changelog:

3.这个时候我们提交代码需要使用 npx cz:  

第一步是选择type,本次更新的类型

第二步选择本次修改的范围(作用域)

  第三步选择提交的信息

 第四步提交详细的描述信息

第五步是否是一次重大的更改

第六步是否影响某个open issue

4、可以通过git log来查看本次提交

二、代码提交验证 

1.安装 @commitlint/config-conventional 和 @commitlint/cli

2.在根目录创建commitlint.config.js文件,配置commitlint

3.使用husky生成commit-msg文件,验证提交信息:

4、修改package.json配置,使用npm run commit提交更方便


一、代码提交风格

通常我们的git commit会按照统一的风格来提交,这样可以快速定位每次提交的内容,方便之后对版本进行控制。

但是如果每次手动来编写这些是比较麻烦的事情,我们可以使用一个工具:Commitizen

Commitizen 是一个帮助我们编写规范 commit message 的工具;

1.安装Commitizen
npm install commitizen -D
2.安装cz-conventional-changelog,并且初始化cz-conventional-changelog:
npx commitizen init cz-conventional-changelog --save-dev --save-exact

这个命令会帮助我们安装cz-conventional-changelog:

并且在package.json中进行配置:

3.这个时候我们提交代码需要使用 npx cz:  
npx cz

回车后:

  • 第一步是选择type,本次更新的类型
Type作用
feat新增特性 (feature)
fix修复 Bug(bug fix)
docs修改文档 (documentation)
style代码格式修改(white-space, formatting, missing semi colons, etc)
refactor代码重构(refactor)
perf改善性能(A code change that improves performance)
test测试(when adding missing tests)
build变更项目构建或外部依赖(例如 scopes: webpack、gulp、npm 等)
ci更改持续集成软件的配置文件和 package 中的 scripts 命令,例如 scopes: Travis, Circle 等
chore变更构建流程或辅助工具(比如更改测试环境)
revert代码回退
  • 第二步选择本次修改的范围(作用域)

? 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 86 chars):

提交描述的具体信息

  •  第四步提交详细的描述信息

 ? Provide a longer description of the change: (press enter to skip)

是否提交详细的描述信息

  • 第五步是否是一次重大的更改

 ? Are there any breaking changes?

是否是一次重大的更改(默认no)

  • 第六步是否影响某个open issue

? Does this change affect any open issues?  

是否影响某个open issue(一般在开源项目中,公司里一般no)

4、可以通过git log来查看本次提交
git log

二、代码提交验证 

如果我们按照cz来规范了提交风格,但是依然有同事通过 git commit 按照不规范的格式提交应该怎么办呢?

  • 我们可以通过commitlint来限制提交;

1.安装 @commitlint/config-conventional 和 @commitlint/cli
npm i @commitlint/config-conventional @commitlint/cli -D
2.在根目录创建commitlint.config.js文件,配置commitlint
module.exports = {
  extends: ['@commitlint/config-conventional']
}
3.使用husky生成commit-msg文件,验证提交信息:
npx husky add .husky/commit-msg "npx --no-install commitlint --edit $1"
4、修改package.json配置,使用npm run commit提交更方便

npm run commit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值