写一个体验良好的git commit
一直在使用git也看过格式各样commit log , review 代码时最刺激的是看到这类 “.” 应付差事,还有 "fix bug","fix" 等等
沟通五何原则
简单介绍下沟通的“五何原则”,因为commit log 是写给自己和团队其他成员看的,需要认真对待,前期debug没时间想清楚commit log , 后期任务完成也可以压缩多个提交为一个,单个提交可以使用 --amend 来修改等等,进入正题就是沟通的时候要跟别人讲清楚
- 何时
- 何地
- 因何故
- 需要何人
- 做何事
这个原则我觉的可以借鉴和发散一下应用到commit log 上,何时(在什么时间点log上有),何地(关联修改了哪些,文件,影响哪些功能),因何故(修改bug,代码重构,新需求开发),需要何人(引入了哪些外部资源),做何事(把本次提交主要解决了什么问题描述清楚)
我常用前缀命名
我也反思过怎么样子写一个自己看着舒服,有一定命名约定的commit,以下是我自己经常用到的前缀Action描述,借鉴阮一峰老师的思路,希望可以抛砖引玉
Debug : 正在对一个文件进行调试,中间在修改
Done : 结束debug,或是重构,完成了进行中的活动
Trim : 表示对一个文件进行整理:空格,函数位置,缩进
Init : 新建分支,会写一个描述,如有任务,附带任务的链接
Fix : fix bug
Mod : remove unused code, 表示修改(Modify)
Add : a new module to have faster process, 表示新增(Add)
Rem : deprecate unused modules, 表示移除(Remove)
Ref : improved the implementation of module X, 表示重构(Refactory)
Branch : 新分支的建立
Dev : 新功能开发中
Merge : 分支合并
我经常使用的commit格式
commit 947c4962a1013005969e934a66c70d2b52dbb132
Author: buoge <wuchuanbo@zaozuo.com>
Date: Thu Jun 7 16:24:58 2018 +0800
Mod: CpaReportDaiy activated_at as report_date filter is null
commit b3ccb225d806c5e7d0fa8a536a12b7a41951b67f
Author: buoge <wuchuanbo@zaozuo.com>
Date: Thu Jun 7 14:38:00 2018 +0800
Fix: user registe num count bug when can not get idfa and return 0000*
commit 379e316620addc8b3db1d01595a97053300eacb5
Author: buoge <wuchuanbo@zaozuo.com>
Date: Wed Jun 6 18:06:15 2018 +0800
Debug: CpaReportDaiy_v2
commit 362bf11b450675120ef5400130e68398848e694f
Author: buoge <wuchuanbo@zaozuo.com>
Date: Wed Jun 6 16:39:40 2018 +0800
Ref: genUserReport to aggregateUserReport
commit ec061ad3b385209de0e5efb292d8b64596f3559e
Author: buoge <wuchuanbo@zaozuo.com>
Date: Wed Jun 6 16:29:09 2018 +0800
Mod: CpaReportDaiy_v2, generateUserReport new aggregation algorithm
推荐使用的格式:
第一行应该少于50个字。 随后是一个空行 第一行题目也可以写成:Fix issue #8976
永远不在 git commit 上增加 -m 或 --message= 参数,而单独写提交信息
一个不好的例子 git commit -m "Fix login bug"
一个推荐的 commit message 应该是这样:
Redirect user to the requested page after login
https://trello.com/path/to/relevant/card
Users were being redirected to the home page after login, which is less
useful than redirecting to the page they had originally requested before
being redirected to the login form.
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
注释最好包含一个连接指向你们项目的issue/story/card
一个完整的连接比一个 issue numbers 更好提交信息中包含一个简短的故事,能让别人更容易理解你的项目注释要回答如下信息
为什么这次修改是必要的?
要告诉 Reviewers,你的提交包含什么改变。让他们更容易审核代码和忽略无关的改变。
- 如何解决的问题?**
这可不是说技术细节。看下面的两个例子:
Introduce a red/black tree to increase search speed
Remove , which was causing
如果你的修改特别明显,就可以忽略这个。
这些变化可能影响哪些地方?
这是你最需要回答的问题。因为它会帮你发现在某个 branch 或 commit 中的做了过多的改动。一个提交尽量只做1,2个变化。
- 你的团队应该有一个自己的行为规则,规定每个 commit 和 branch 最多能含有多少个功能修改。
小提示
使用 fix, add, change 而不是 fixed, added, changed
永远别忘了第2行是空行
用 Line break 来分割提交信息,让它在某些软件里面更容易读
请将每次提交限定于完成一次逻辑功能。并且可能的话,适当地分解为多次小更新,以便每次小型提交都更易于理解。
Examples of good practice:
范例一:
Fix bug where user can't signup.
[Bug #2873942]
Users were unable to register if they hadn't visited the plans
and pricing page because we expected that tracking
information to exist for the logs we create after a user
signs up. I fixed this by adding a check to the logger
to ensure that if that information was not available
we weren't trying to write it.
Redirect user to the requested page after login
https://trello.com/path/to/relevant/card
Users were being redirected to the home page after login, which is less
useful than redirecting to the page they had originally requested before
being redirected to the login form.
* Store requested path in a session variable
* Redirect to the stored location after successfully logging in the user
范例二:
commit 3114a97ba188895daff4a3d337b2c73855d4632d
Author: [removed]
Date: Mon Jun 11 17:16:10 2012 +0100
Update default policies for KVM guest PIT & RTC timers
The default policies for the KVM guest PIT and RTC timers
are not very good at maintaining reliable time in guest
operating systems. In particular Windows 7 guests will
often crash with the default KVM timer policies, and old
Linux guests will have very bad time drift
Set the PIT such that missed ticks are injected at the
normal rate, ie they are delayed
Set the RTC such that missed ticks are injected at a
higher rate to "catch up"
This corresponds to the following libvirt XML
<clock offset='utc'>
<timer name='pit' tickpolicy='delay'/>
<timer name='rtc' tickpolicy='catchup'/>
</clock>
And the following KVM options
-no-kvm-pit-reinjection
-rtc base=utc,driftfix=slew
This should provide a default configuration that works
acceptably for most OS types. In the future this will
likely need to be made configurable per-guest OS type.
Closes-Bug: #1011848
Change-Id: Iafb0e2192b5f3c05b6395ffdfa14f86a98ce3d1f
补充一个相关的链接:
“如何优雅的使用git:”
http://blog.waterstrong.me/master-git/http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
commit log 不是万能的, 不看代码改动是万万不能的,最终代码评审还是要看代码改动来检查和确认,一个简明扼要的log能提高这个的效率
写一个体验良好的git commit的更多相关文章
- 如何写好 Git commit messages
导语:任何软件项目都是一个协作项目,它至少需要2个开发人员参与,当原始的开发人员将项目开发几个星期或者几个月之后,项目步入正规.不过他们或者后续的开发人员仍然需要经常提交一些代码去修复bug或者实现新 ...
- 如何写好git commit message
1.触发事件 我有这样一个版本库,里面包含两个学习用的练习项目:BookStore(以下简称BS)和PictureFriend(以下简称PF) 我在更改PF以后,未进行提交,同时又到BS中优化了一下文 ...
- 我是怎么写 Git Commit message 的?
目录 作用 用的什么规范? type scope subject body footer 参考文章 用的什么辅助工具? 作用 编写格式化的 commit message 能够大大提高代码的维护效率. ...
- 第二章-如何使用github建立一个HelloWorld项目,git的add/commit/push/pull/fetch/clone等基本命令用法。--答题人:杨宇杰
1.配置Git 首先在本地创建ssh 秘钥:在git bash输入: $ ssh-keygen -t rsa -C "your_email@youremail.com" eg:$ ...
- git 场景 :从一个分支cherry-pick多个commit
场景: 在branch1开发,进行多个提交,这是切换到branch2,想把之前branch1分支提交的commit都[复制]过来,怎么办? 首先切换到branch1分支,然后查看提交历史记录,也可以用 ...
- github 使用“git commit -m"命令时候出现的一个小问题
git commit -m 使用问题 今天提交文件到github,步骤是: git add abc.py (abc.py是我当前随意写的一个文件名) git commit -m 'add codes ...
- Python+Flask+Gunicorn 项目实战(一) 从零开始,写一个Markdown解析器 —— 初体验
(一)前言 在开始学习之前,你需要确保你对Python, JavaScript, HTML, Markdown语法有非常基础的了解.项目的源码你可以在 https://github.com/zhu-y ...
- 在linux写一个shell脚本用maven git自动更新代码并且打包部署
服务器上必须安装了git maven jdk 并且配置好环境变量 实际服务器中可能运行着多个Java进程,所以重新部署的时候需要先停止原来的java进程,写一个按照名称杀死进程的脚本 kill.sh ...
- Git操作 :从一个分支cherry-pick多个commit到其他分支
在branch1开发,进行多个提交,这时切换到branch2,想把之前branch1分支提交的commit都[复制]过来,怎么办? 首先切换到branch1分支,然后查看提交历史记录,也可以用sour ...
随机推荐
- 【转】【Asp.Net】ASP.Net Response.ContentType 详细列表
不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 text/html 也就是网页格式. 代码如: <% response.ContentType =&quo ...
- e659. 缩放,剪取,移动,翻转图形
AffineTransform tx = new AffineTransform(); tx.scale(scalex, scaley); tx.shear(shiftx, shifty); tx.t ...
- Wellner 自适应阈值二值化算法
参考文档: Adaptive Thresholding for the DigitalDesk.pdf Adaptive Thresholding Using the Integral I ...
- c网络编程-多播
/* 编译通过环境,Windows XP sp2,Windows 2003 server SDK,VC++6.0 sp5. */ /********************************** ...
- pacbio 原始下机数据h5 文件简介
pacbio 采用hdf5文件格式保存原始的下机数据,对于RS 测序系统而言,会产生一个 bas.h5 的文件; 以bas.h5 文件为例,看一下有下机数据中保存了那些信息 h5dump 工具可以用来 ...
- 监听程序未启动或数据库服务未注册到该监听程序。启动该监听程序并注册数据库服务 然后重新运行 em configuration assistant。
在WIN 7/64Bit上安装ORACLE 11gR2后,管理网页Database Control(如:https://localhost:1158/em)始终登录不进去,总是说密码错误,使用配置工具 ...
- 简易2D横版RPG游戏制作
Unity学习笔记1 简易2D横版RPG游戏制作 http://m.blog.csdn.net/article/details?id=24601905
- OpenCV学习:实现简单的图像叠加
本实例使用简单的线性叠加方法来实现两幅图像的叠加,主要使用的知识如下: 1)线性融合 2)addWeighted函数 //! computes weighted sum of two arrays ( ...
- sftp,get命令使用*通配符的方式获取批量的文件
需求描述: 今天在使用sftp进行get文件的时候,有很多文件名类似的文件,以为还是需要一个一个get 后来发现get也可以使用通配符的方式进行匹配获取多个文件,在此记录下 操作过程: 1.通过sft ...
- Java精选笔记_IO流(字节流、InputStream、OutputStream、字节文件、缓冲区输入输出流)
字节流 操作图片数据就要用到字节流. 字符流使用的是字符数组char[],字节流使用的是字节数组byte[]. 字节流读写文件 针对文件的读写,JDK专门提供了两个类,分别是FileInputStre ...