Git commit的一些规范抄录

 


一、Commit message 的格式

每次提交,Commit message 都包括三个部分:Header,Body 和 Footer。

<type>(<scope>):<subject>
// 空一行
<body>
// 空一行
<footer>

其中,Header是必须的,Body和Footer可以省略。

1.1 Header

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

(1)type

用于说明git commit的类别,只允许使用下面的标识。

type类型 说明
feat 新功能(feature)
fix 修补bug
docs 文档(documentation)
style 格式(不影响代码运行的变动)
refactor 重构(即不是新增功能,也不是修改bug的代码变动)
test 增加测试
chore 构建过程或辅助工具的变动
perf 优化相关,如提升性能、体验
revert 回滚到上一个版本
merge 代码合并
sync 同步主线或分支的Bug

(2)scope(可选)

scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。

(3)subject(必须)

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

  • 以动词开头,使用第一人称现在时,比如change,而不是changed或change
  • 第一个字母小写
  • 结尾不加句号或其他标点符号

示例:

fix(DAO):用户查询缺少username属性
feat(Controller):用户查询接口开发

1.2 Body

对本次commit的详细描述,可以分成多行。

More detailed explanatory text, if necessary.  Wrap it to 
about 72 characters or so. 

Further paragraphs come after blank lines.

- Bullet points are okay, too
- Use a hanging indent

1.3 Footer

Footer部分只用于两种情况。

(1) 不兼容变动

如果当前代码与上一个版本不兼容,则 Footer 部分以BREAKING CHANGE开头,后面是对变动的描述、以及变动理由和迁移方法。

BREAKING CHANGE: isolate scope bindings definition has changed.

    To migrate the code follow the example below:

    Before:

    scope: {
      myAttr: 'attribute',
    }

    After:

    scope: {
      myAttr: '@',
    }

    The removed `inject` wasn't generaly useful for directives so there should be no code using it.

(2) 关闭Issue

如果当前 commit 针对某个issue,那么可以在 Footer 部分关闭这个 issue 。

`Closes #234`

一次关闭多个Issue

`Closes #123, #245, #992`

参考:

  1. Commit message 和 Change log 编写指南
  2. 如何规范你的Git commit?
posted @ 2022-03-19 14:17  乞力马扎罗山的雪  阅读(130)  评论(0编辑  收藏  举报

目录导航