一直在使用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. android hardware.c 源码分析

    android的jni通过ID来找hal模块,使用了hw_get_module()函数,本文就通过这个函数的来分析一下hal层的模块是如何匹配的. 首先要了解三个结构体hw_module_t,hw_m ...

  2. 在不指定特殊属性的情况下,哪几种HTML标签可以手动输入文本:()

    A. <TEXTAREA></TEXTAREA> B. <INPUT type=”text”/> C. <INPUT type=”hidden”/> D ...

  3. h264 i p 帧特点

     1.爱无铭(47530789) 2014-2-13 17:07:27 I帧只有intra p帧有inter和intra:B帧一般只用inter  2.  庐舍闲士(361389535) 2014-2 ...

  4. openal 基础知识

    原文地址:http://blog.csdn.net/woker/article/details/8687380 一简介 OpenAL抽象出三种基本对象:buffers(缓冲区).sources(源). ...

  5. Spring-导入和混合配置

    javaConfig模式下: 导入: @Import({XX.class,YY.class,...}) 混合: @ImportResource("classpath:xxx.xml" ...

  6. 第三章 SqlSessionFactoryBean(MyBatis)

    SqlSessionFactoryBean 在基本的 MyBatis 中,session 工厂可以使用 SqlSessionFactoryBuilder 来创建.而在 MyBatis-Spring 中 ...

  7. mybatis由浅入深day01_5.3 Mapper动态代理方法

    5.3 Mapper动态代理方法(程序员只需要写mapper接口(相当于dao接口)) 5.3.1 实现原理(mapper代理开发规范) 程序员还需要编写mapper.xml映射文件 程序员编写map ...

  8. mybatis由浅入深day01_4入门程序_4.6根据用户id(主键)查询用户信息

    4 入门程序 4.1 需求 根据用户id(主键)查询用户信息 根据用户名称模糊查询用户信息 添加用户 删除 用户 更新用户 4.2 环境 java环境:jdk1.7.0_72 eclipse:indi ...

  9. GIS-009-Cesium 使用

    //加载ArcGIS 发布的地图服务MapServervar url='http://Jason:6080/arcgis/rest/services/SampleWorldCities/MapServ ...

  10. Effective C++ —— 让自己习惯C++(一)

    条款01 : 视C++为一个语言联邦 C++ == C(C基本语法) + Object-Oriented C++(类,封装,继承,多态……) + Template C++(泛型编程) + STL(容器 ...