a)提供更多的历史信息,方便快速浏览和项目接入以及交接
b)可以过滤某些commit(比如文档改动),便于快速查找信息
c)可以直接从commit生成Change log(需要工具支持)
目前git commit规范使用较多的是Angular 团队的规范。
模板格式:
<type>(<scope>): <subject>
<空行>
<body>
<空行>
<footer>
具体字段解释参考:
https://www.conventionalcommits.org/zh-hans/v1.0.0-beta.4/
a)首先将下面内容拷贝至:~/.git-commit-template
# Type(<scope>): <subject> # <body> # <footer> # type 字段包含: # feat:新功能(feature) # fix:修补bug # docs:文档修改(documentation) # style: 代码格式修改(不影响代码运行的变动) # refactor:代码重构(即不是新增功能,也不是修改bug的代码变动) # test:测试用例修改 # chore:其他修改, 比如构建流程, 依赖管理,或辅助工具的变动 # # scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等。 # # subject是 commit 目的的简短描述,不超过50个字符 # # Body 部分是对本次 commit 的详细描述,每行不超过70个字符,可以分成多行 # 50/70规则参见: # https://stackoverflow.com/questions/2290016/git-commit-messages-50-72-formatting # # Footer用来关闭 Issue或以BREAKING CHANGE开头,后面是对变动的描述、 # 以及变动理由和迁移方法 # # 关于git commit常用规范简单介绍,参见这里 #https://www.conventionalcommits.org/zh-hans/v1.0.0-beta.4/ |
---|
b)配置git template:
git config --global commit.template ~/.git-commit-template
c) 提交代码,按照模板填写commit
git commit
commit时按模板填写,注意空行
提交完成后git log查看
以上就完成了git commit提交规范的手工配置,如果希望在提交时自动按提示完成commit输入,则参考下面第3小节
目前比较流行的工具是commitizen:
https://github.com/commitizen/cz-cli
安装过程如下:
ubuntu安装node和npm,其他系统类似:
apt install nodejs-dev
apt install npm
commitizen需要node版本>8.0,满足要求的跳过。ubuntu升级最新稳定版方法如下:
npm cache clean -f
sudo npm install -g n
sudo n stable
a)安装
npm install -g commitizen
b)配置项目初始化package.json
进入git项目根目录,执行
npm init --yes
c)配置Angular规范的Commit message
commitizen init cz-conventional-changelog --save --save-exact
安装完成之后,当需要git commit的时候换成 git cz 即可,commitizen 会按照规范提示commit msg的书写。例如:
changelog工具用于根据argular规范的commit message生成项目changlog文档
安装如下2个工具:
npm install -g conventional-changelog
npm install -g conventional-changelog-cli
当完成commit之后,使用如下命令生成changelog
conventional-changelog -p angular -i CHANGELOG.md -s
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有