linux内核 git commit规范,用工具思路来规范化 git commit message

为什么要规范 Git Commit Message

发生问题快速识别问题代码

commit和代码建立联系,和相关prd、bug予以关联。

如何写出规范化的 Git Commit Message

选用当前业界内应用比较广泛的 Angular Git Commit Guidelines

():

type:commit的类型:feat fix refactor docs style test chore

scope:commit 影响的范围, 比如: route, component, utils, build...

subject:commit 的概述

以动词开头,使用第一人称现在时,比如change,而不是changed或changes

第一个字母小写(可以使用中文)

结尾没有符号

body:commit 具体修改内容, 可以分为多行

footer:一些备注, 通常是 BREAKING CHANGE 或修复的 bug 的链接

项目使用参考步骤

1.Commitizen: 替代你的 git commit

commitizen/cz-cli, 我们需要借助它提供的 git cz 命令替代我们的 git commit 命令, 帮助我们生成符合规范的 commit message.

除此之外, 我们还需要为 commitizen 指定一个 Adapter 比如: cz-conventional-changelog (一个符合 Angular团队规范的 preset). 使得 commitizen 按照我们指定的规范帮助我们生成 commit message.

yarn add --dev commitizen cz-conventional-changelog

package.json中配置:

"script": {

...,

"commit": "git-cz",

},

"config": {

"commitizen": {

"path": "node_modules/cz-conventional-changelog"

}

}

如果全局安装过 commitizen, 那么在对应的项目中执行 git cz or npm run commit 都可以

2.Commitlint: 校验你的 message

commitlint: 可以帮助我们 lint commit messages,校验的配置推荐 [@commitlint/config-conventional]() (符合 Angular团队规范).

话不多说直接按照:

yarn add --dev @commitlint/config-conventional @commitlint/cli

同时需要在项目目录下创建配置文件 .commitlintrc.js, 写入:

module.exports = {

extends: [

'@commitlint/config-conventional'

],

rules: {

}

};

3.结合 Husky

yarn add --dev husky

package.json 中添加:

"husky": {

"hooks": {

...,

"commit-msg": "commitlint -e $GIT_PARAMS"

}

},

参考资料

优雅的提交你的 Git Commit Message

Commit message 和 Change log 编写指南

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值