Git Commit Message 规范
今天来说说团队开发中,对于 Git commit message 规范问题。
社区上有各种 Commit message 的规范,本文介绍 Angular 规范,目前使用较广,比较合理和系统化,并且有配套的工具。
1. 规范 Commit Msg 的作用
1) 提供更多的历史信息,方便快速浏览
例如,命令显示上次发布后的变动,每个 commit 占据一行。只看首行,就知道某次 commit 的目的。
$ git log <last tag> HEAD --pretty=format:%s
2) 可以过滤某些 commit ,便于快速查找信息
例如,下面的命令过滤仅显示本次发布新增加的功能。
$ git log <last release> HEAD --grep feature
3) 可以直接从 commit 生成 Change Log
Change Log 是发布新版本时,用来说明与上一版本差异的文档。
2. Angular 规范的 Commit Msg 语法
每一次提交,Commit message 都包括 3 个部分: Header, Body 和 Footer 。
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
其中,Header 是必需的, Body 和 Footer 可以省略。
Commit Msg 的任何一行都不得超过 100 个字符。这样是为了在 GitHub 以及各种 Git 工具中更容易阅读。
2.1. Message Header
Header 部分只有一行,它包含对更改的简单描述,其中包括 「类型」( type )、「可选范围」( scope ) 和 「主题」( subject )。
//Message Header Demo
fix($compile): couple of unit tests for IE9
style($location): add couple of missing semi colons
feat($compile): simplify isolate scope bindings
2.1.1. 类型 type
type 用于说明 commit 的类别,只允许使用一下 7 个标示。
feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试
chore:构建过程或辅助工具的变动
2.1.2. 影响范围 scope
「范围」可以是指定提交更改位置的任何内容。例如 browser 、 $compile 、 SrootScope 、 ngHref 、 ngClick 、 ngView 等。
如果没有合适的「范围」,可以用 * 。
2.1.3 主题 subject
subject 是 commit 目的的简单描述,不超过 50 个字符。
* 使用祈使句,并且以第一人称现在时。
* 首字母不要大写
* 结尾 不要 加句号(dot)
2.2. Message Body
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) 使用第一人称现在时。
2) 应该说明代码变动的动机,以及与以前行为的对比。
2.3. Footer
2.3.1. 重大更改 Breaking Changes
所有的「重大更改」必须在 Footer 作为「重大更改块」被提及到,它应该以 BREAKING CHANGE: 开头,后面跟着一个空格或者两个空行。然后,Commit Msg 的其余部分是对更改,理由和迁移说明的描述。
REAKING CHANGE:
isolate scope bindings definition has changed and
the inject option for the directive controller injection was removed.
To migrate the code follow the example below:
Before:
scope: {
myAttr: 'attribute',
myBind: 'bind',
myExpression: 'expression',
myEval: 'evaluate',
myAccessor: 'accessor'
}
After:
scope: {
myAttr: '@',
myBind: '@',
myExpression: '&',
// myEval - usually not useful, but in cases where the expression is assignable, you can use '='
myAccessor: '=' // in directive's template change myAccessor() to myAccessor
}
The removed `inject` wasn't generaly useful for directives so there should be no code using it.
2.3.2. 关闭 Issue (Referencing Issues)
如果当前 commit 针对某个 issue ,那么可以在 Footer 部分关闭这个 issue 。Closes 关键字为前缀。
Closes #123
也可以一次关闭多个 issue 。
Closes #123, #243, #545
2.4. 还原 (Revert)
如果当前的 commit 是还原到之前的 commit,那么当前 Commit msg Header 要以 revert: 开头,并且后面紧跟着还原 Commit 的 Header 。这时 Body 里面要以 This reverts commit <hash> 固定式,其中 <hash> 是 commit 的 SHA 标示符。
revert: feat(pencil): add 'graphiteWidth' option
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
参考文献
Angular 规范: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit
阮一峰 博客: http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
Git Commit Message 规范的更多相关文章
- 如何写好git commit message
1.触发事件 我有这样一个版本库,里面包含两个学习用的练习项目:BookStore(以下简称BS)和PictureFriend(以下简称PF) 我在更改PF以后,未进行提交,同时又到BS中优化了一下文 ...
- 我是怎么写 Git Commit message 的?
目录 作用 用的什么规范? type scope subject body footer 参考文章 用的什么辅助工具? 作用 编写格式化的 commit message 能够大大提高代码的维护效率. ...
- git第四节----git commit message
@git commit message 什么是git commit message :git commit -m '每次提交时编辑的内容' git commit message的好处: 1 ...
- 自家公司关于git commit 的规范
代码提交的commit info提个建议,fix的issue是哪个issue?都要有明确的链接.推荐方式:1.建立issue,说明问题的背景和原因.http://git.startdt.net/pay ...
- Git commit message和工作流规范
目的 统一团队Git commit日志标准,便于后续代码review,版本发布以及日志自动化生成等等. 统一团队的Git工作流,包括分支使用.tag规范.issue等 Git commit日志参考案例 ...
- git使用总结(包含git commit message 和 changelog 工具的介绍)
[git的配置] 1.配置用户名和邮箱: 分为全局配置和局部配置 --system 系统配置 --global 全局配置 --local 局部配置 Git读取时:优先从local>glo ...
- commitizen和cz-customizable配置git commit message
起因 团队对提交的commit message格式有约定俗称的要求,但是没有一个统一的规范,导致大家提交的commit message或多或少不太一样.因此,需要一个工具来帮助大家统一commit m ...
- git commit的规范
https://www.yuque.com/fe9/basic/nruxq8#6c228def 制定一个 git commit 信息的提交规范是开发团队工作流必不可少的环节.试想一下,如果查看主分支上 ...
- 优化 Git Commit Message
目前很多项目都是通过 Git 进行管理的,Git 每次提交代码的过程中 提交说明 commit message 是必须的.但仅仅必须是不够的,好的提交说明可以帮助我们提高项目的整体质量. 作用与优点 ...
随机推荐
- tomcat标准化安装
操作系统说明: 操作系统 版本 linux red hat release 6.4 关键软件包说明: 软件包 版本 目录 运行用户 jdk-7u79-linux-x64.gz 1.7 /usr/loc ...
- H5C3--拖拽接口的使用和实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- hdu 2087剪花布条 (KMP入门 子串出现的次数和子串个数)
剪花布条 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- jQuuery Mobile 移动端开发框架
jQuery Mobile 是创建移动 web 应用程序的框架. jQuery Mobile 适用于所有流行的智能手机和平板电脑. jQuery Mobile 使用 HTML5 和 CSS3 通过尽可 ...
- c标签 if else c标签 总结
[b]STL标签用法 关键字:JSTL标签.<c:choose>.<c:forEach>.<c:forTokens>.<c:if>.<c:impo ...
- PHP原生DOM对象操作XML的方法解答
创建一个新的XML文件,并且写入一些数据到这个XML文件中. /** 创建xml文件*/ $info = array(array('obj' => 'power','info' => 'p ...
- 带三角形下标的提示框(按钮button)
HTML:<div class="leaflet-popup-content-wrapper"> <div class="leaflet-popup-c ...
- oracle-Immediate
从shutdown immediate命令发布起,禁止建立任何新的oracle连接 未提交的事务被回退.因此,处于一个事务中间的用户将失去所有未提交的劳动成果. oracle不等待客户断开连接.任何未 ...
- Kafka Connect HDFS
概述 Kafka 的数据如何传输到HDFS?如果仔细思考,会发现这个问题并不简单. 不妨先想一下这两个问题? 1)为什么要将Kafka的数据传输到HDFS上? 2)为什么不直接写HDFS而要通过Kaf ...
- Mybatis中输出映射resultType与resultMap的区别
Mybatis中输出映射resultType与resultMap的区别 (原文地址:http://blog.csdn.net/acmman/article/details/46509375) 一.re ...