一直在使用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 commit的更多相关文章

  1. 如何写好 Git commit messages

    导语:任何软件项目都是一个协作项目,它至少需要2个开发人员参与,当原始的开发人员将项目开发几个星期或者几个月之后,项目步入正规.不过他们或者后续的开发人员仍然需要经常提交一些代码去修复bug或者实现新 ...

  2. 如何写好git commit message

    1.触发事件 我有这样一个版本库,里面包含两个学习用的练习项目:BookStore(以下简称BS)和PictureFriend(以下简称PF) 我在更改PF以后,未进行提交,同时又到BS中优化了一下文 ...

  3. 我是怎么写 Git Commit message 的?

    目录 作用 用的什么规范? type scope subject body footer 参考文章 用的什么辅助工具? 作用 编写格式化的 commit message 能够大大提高代码的维护效率. ...

  4. 第二章-如何使用github建立一个HelloWorld项目,git的add/commit/push/pull/fetch/clone等基本命令用法。--答题人:杨宇杰

    1.配置Git 首先在本地创建ssh 秘钥:在git bash输入: $ ssh-keygen -t rsa -C "your_email@youremail.com" eg:$ ...

  5. git 场景 :从一个分支cherry-pick多个commit

    场景: 在branch1开发,进行多个提交,这是切换到branch2,想把之前branch1分支提交的commit都[复制]过来,怎么办? 首先切换到branch1分支,然后查看提交历史记录,也可以用 ...

  6. github 使用“git commit -m"命令时候出现的一个小问题

    git commit -m 使用问题 今天提交文件到github,步骤是: git add abc.py (abc.py是我当前随意写的一个文件名) git commit -m 'add codes ...

  7. Python+Flask+Gunicorn 项目实战(一) 从零开始,写一个Markdown解析器 —— 初体验

    (一)前言 在开始学习之前,你需要确保你对Python, JavaScript, HTML, Markdown语法有非常基础的了解.项目的源码你可以在 https://github.com/zhu-y ...

  8. 在linux写一个shell脚本用maven git自动更新代码并且打包部署

    服务器上必须安装了git maven jdk 并且配置好环境变量 实际服务器中可能运行着多个Java进程,所以重新部署的时候需要先停止原来的java进程,写一个按照名称杀死进程的脚本 kill.sh ...

  9. Git操作 :从一个分支cherry-pick多个commit到其他分支

    在branch1开发,进行多个提交,这时切换到branch2,想把之前branch1分支提交的commit都[复制]过来,怎么办? 首先切换到branch1分支,然后查看提交历史记录,也可以用sour ...

随机推荐

  1. 关于Cocos2d-x中多边形物理刚体的设置

    1.如果想要设置某个物体有多边形的刚体,这样可以更精确地进行碰撞检测,可以用以下的方法 auto hero = PlaneHero::create(); addChild(hero, 0, HERO_ ...

  2. C的内存四大区

    前提 看视频得来的内容,只知道不止4个区,但主要是这4个区. 四区 静态区 用于存放所有的全局变量和静态变量. ; //静态区 int main(){ ; //静态区 ; } 代码区 就是存放程序的执 ...

  3. 转:Python操作SQLServer示例

    注:此文也是转载,2018年1月发现此文阅读量过万,略感不安.当时只是为了自己存档学习,未粘此文的原始连接.如有侵权,通过即删除,敬请谅解! 从网上找的,估计原文是:Python操作SQLServer ...

  4. R语言绘图边框

    在R语言中, 绘图边框一共有3个区域: device region : figure region : plot region   : 在描述不同区域大小的时候,有对应的不同参数: din : 返回d ...

  5. redis windows 版配置使用

    网上下载windows版的redis 在D盘新建redis目录 把下载的redis压缩包解压到redis目录,如图: 打开配置文件 redis.windows.conf 把 SECURITY下的req ...

  6. Linux配置防火墙,开启80port、3306port 可能会遇到的小问题

     vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(同意80端口通 ...

  7. mysql通过mysql_install_db初始化数据目录时使用--user选项的作用是什么?

    需求描述: mysql数据库通过mysql_install_db初始化数据目录时,使用了--user选项,这里记录下该参数的作用 参数解释: 1.--user的作用:就是以哪个操作系统用户来执行mys ...

  8. nginx配置语法

    http://baijiahao.baidu.com/s?id=1604485941272024493&wfr=spider&for=pc http://blog.csdn.net/h ...

  9. mybatis由浅入深day01_ 7输入映射(7.1传递pojo的包装对象_7.2#{}与${}_7.3传递简单类型_7.4传递pojo对象_7.5传递hashmap)

    7 输入映射 通过parameterType指定输入参数的类型,类型可以是简单类型.hashmap.pojo的包装类型. 7.1 传递pojo的包装对象 7.1.1 需求 完成用户信息的综合查询,需要 ...

  10. php 网络爬虫,爬一下花瓣的图片

    今天无聊看在知乎上看到有人写网络爬虫爬图片( ̄▽  ̄) 传送门: 福利 - 不过百行代码的爬虫爬取美女图:https://zhuanlan.zhihu.com/p/24730075 福利 - 不过十行 ...