怎样写好Git的commit信息

引言

这篇文章我翻译自How to Write a Git Commit Message,由于文章篇幅太多,全部翻译下来太浪费时间了,因此我把一些重要的地方全部翻译完了,如果英语好的请读原文,英语水平不算太好地同学,可以参考我的翻译来理解原文。如果大家能把我翻译的部分看完,相信大家就可以写出一个好的commit信息了。这篇文章主要介绍的是写好Git的commit信息我们需要遵守的一些规则并说明为什么好的commit信息是如此重要,作者都给出了很好地解释。

文章作者的Github主页为:https://github.com/cbeams,从他的主页可以看出他是spring-framework和gradle的contributor.

为什么好的commit信息如此重要?

如果你去随便找几个Git仓库的日志,你会发现这些仓库的commit信息或多或少地有些混乱。举个例子,大家来看一看我前些日子提交到Spring代码的commit日志

$ git log --oneline -5 --author cbeams --before "Fri Mar 26 2009"

e5f4b49 Re-adding ConfigurationPostProcessorTests after its brief removal in r814. @Ignore-ing the testCglibClassesAreLoadedJustInTimeForEnhancement() method as it turns out this was one of the culprits in the recent build breakage. The classloader hacking causes subtle downstream effects, breaking unrelated tests. The test method is still useful, but should only be run on a manual basis to ensure CGLIB is not prematurely classloaded, and should not be run as part of the automated build.
2db0f12 fixed two build-breaking issues: + reverted ClassMetadataReadingVisitor to revision 794 + eliminated ConfigurationPostProcessorTests until further investigation determines why it causes downstream tests to fail (such as the seemingly unrelated ClassPathXmlApplicationContextTests)
147709f Tweaks to package-info.java files
22b25e0 Consolidated Util and MutableAnnotationUtils classes into existing AsmUtils
7f96f57 polishing

呀!比较一下同一个仓库中最近刚刚提交的commit信息吧。

$ git log --oneline -5 --author pwebb --before "Sat Aug 30 2014"

5ba3db6 Fix failing CompositePropertySourceTests
84564a0 Rework @PropertySource early parsing logic
e142fd1 Add tests for ImportSelector meta-data
887815f Update docbook dependency and generate epub
ac8326d Polish mockito usage

你更喜欢看哪个?前者在长度和形式上都有很大地不同; 而后者是简洁和一致的。前者是通常情况下都会出现的状况; 而后者绝不会偶然发生。然而许多仓库地日志都像前者,当然也有例外地,比如Git项目本身就是一个很好地例子。看看Spring Boot,或者是Tim Pope管理地仓库。

这些仓库地贡献者都知道一个构思好地commit信息是与开发同伴或未来的自己交流改动的最好方式。diff 命令会告诉你改动了什么,但是只有commit信息会告诉你为什么那样去改动。Peter Hutterer很好地解释了这点:

重新建立一段代码的背景情况是会浪费很多地时间。我们不能完全避免它,所以我们应该尽量去减少它。commit信息正好可以做到这点,因此,commit信息也可以表明一个开发者是否是个好地合作者。

If you haven’t given much thought to what makes a great Git commit message, it may be the case that you haven’t spent much time using git log and related tools. 这里有个恶性循环: because the commit history is unstructured and inconsistent, one doesn’t s

  • 11
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值