Git Commit规范指南

Git Commit规范指南

1、优点

  • 可读性好,清晰,不必深入看代码即可了解当前commit的作用
  • 为 Code Reviewing做准备
  • 方便跟踪工程历史
  • 让其他的开发者在运行 git blame 的时候想跪谢
  • 提高项目的整体质量,提高个人工程素质

2、Commit message 格式

1
2
3
4
5
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>

其中header部分是必须的,body跟footer可以忽略

3、Header

header部分只有一行,包括三个字段:type(必需)scope(可选)subject(必需)

3.1、Header type的类别:

1
2
3
4
5
6
7
8
9
10
feat    : 添加新特性、新功能
fix : 修复bug
docs : 仅仅修改了文档
style : 仅仅修改了空格、格式缩进、逗号等等,不改变代码逻辑,不影响代码运行的变动
refact : 代码重构,既不是新功能增加,也不是修复bug的改动
perf : 优化相关,比如性能测试、体验等
test : 增加测试用例,包括单元测试、集成测试等
chore : 改变构建流程、或者增加依赖库、工具等
tips : 增加一些提示信息,例如错误提示等
del : 删除

如果type类型为 featfix 时,则该commit将肯定出现在change log之中

3.2、Header scope

scope用于说明commit 影响的范围,比如数据层、控制层、视图层等等,根据项目不同而不同
如果你的修改影响了不止一个 scope,可以使用 * 代替

3.3、Header subject

subject是commit的简短描述,不超过50个字符

4、如何通过commit关闭issue

1
2
3
4
5
6
7
8
9
close #1024
closes #1024
closed #1024
fix #1024
fixes #1024
fixed #1024
resolve #1024
resolves #1024
resolved #1024

完整写法:git commit -m ‘fix($test):修改测试环境下部分bug closes #1024’

参考文档

# git
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×