一直在使用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. selenium测试(Java)--学习总结

  2. BaaS后端即服务 - 概念篇

    摘要: 什么是BaaS? BaaS(Backend as a Service)是一种新型的云服务,旨在为移动和Web应用提供后端云服务,包括云端数据/文件存储.账户管理.消息推送.社交媒体整合等.Ba ...

  3. 【转】C# 调用WebService的方法

    很少用C#动态的去调用Web Service,一般都是通过添加引用的方式,这样的话是自动成了代理,那么动态代理调用就是我们通过代码去调用这个WSDL,然后自己去生成客户端代理.更多的内容可以看下面的两 ...

  4. bcm53344 gpio驱动分析

    /********************************************************************************* * 1.查看代码是在vim下,使用 ...

  5. 第二百九十五节,python操作redis缓存-字符串类型

    python操作redis缓存-字符串类型 首先要安装redis-py模块 python连接redis方式,有两种连接方式,一种是直接连接,一张是通过连接池连接 注意:以后我们都用的连接池方式连接,直 ...

  6. (转)x264源码分析(1):main、parse、encode、x264_encoder_open函数代码分析

    转自:http://nkwavelet.blog.163.com/blog/static/2277560382013103010312144/ x264版本:   x264-snapshot-2014 ...

  7. MyEclipse 对项目进行build path无效

    今天发现昨天从svn下载下来的项目在MyEclipse中无法build path .提示no actions available 在网上找了下,是由于.projects文件的问题,须要在当中的natu ...

  8. 小明A+B(杭电2096)

    /*小明A+B Problem Description 小明今年3岁了, 如今他已经可以认识100以内的非负整数, 而且可以进行100以内的非负整数的加法计算. 对于大于等于100的整数, 小明仅保留 ...

  9. spark on yarn(zookeeper 配置)

    http://database.51cto.com/art/201404/435630.htm

  10. SQL中查询语句的使用

    常用SQL查询语句 - myLittleGarden - 博客园 http://www.cnblogs.com/sunada2005/p/3411873.html 一.简单查询语句 1. 查看表结构 ...