Git提交消息:50/72格式 [英] Git Commit Messages : 50/72 Formatting

查看:77
本文介绍了Git提交消息:50/72格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tim Pope在他的博客文章中提出了一个特定的git commit消息风格:
查看完整大小



有一些提交有总结线比这个情节可以持续更长(一些更长),而不会使有趣的部分看起来像一条线。 (可能有一些奇特的统计技术可以将这些数据合并到这里,但噢,以及:))。

如果您想查看原始长度:

  cd / path / to / repo 
git shortlog | grep -e'^'| sed's / [[:space:]] \ + \(。* \)$ / \1 /'| awk'{print length($ 0)}'

或基于文本的直方图:

  cd / path / to / repo 
git shortlog | grep -e'^'| sed's / [[:space:]] \ + \(。* \)$ / \1 /'| awk'{lens [length($ 0)] ++;} END {for(len in lens)print len,len [len]}'| sort -n


Tim Pope argues for a particular git commit message style in his blog post: http://www.tpope.net/node/106

Here is a quick summary of what he recommends:

  • First line is 50 characters or less
  • Then a blank line
  • Remaining text should be wrapped at 72 characters

His blog post gives the rationale for these recommendations (which I will call "50/72 formatting" for brevity):

  • In practice, some tools treat the first line as a subject line and the second paragraph as a body (similar to email)
  • git log does not handle wrapping, so it is hard to read if lines are too long.
  • git format-patch --stdout converts commits to email -- so to play nice it helps if your commits are already wrapped nicely.
  • a point I would like to add that I think Tim would agree with: the act of summarizing your commit is a good practice inherently in any version control system. It helps others (or a later you) find relevant commits more quickly.

So, I have a couple of parts to my question:

  • What chunk (roughly) of the 'thought leaders' or 'experienced users' of git embrace the 50/72 formatting style? I ask this because sometime newer users don't know or don't care about community practices.
  • For those that don't use this formatting, is there a principled reason for using a different formatting style? (Please note that I'm looking for an argument on the merits, not "I've never heard of it" or "I don't care.")
  • Empirically speaking, what percentage of git repositories embrace this style? (In case someone wants to do an analysis on GitHub repositories... hint, hint.)

My point here is not to recommend the 50/72 style or shoot down other styles. (To be open about it, I do prefer it, but I am open to other ideas.) I just want to get the rationale for why people like or oppose various git commit message styles. (Feel free to bring up points that haven't been mentioned, too.)

解决方案

Regarding the "summary" line (the 50 in your formula), the Linux kernel documentation has this to say:

For these reasons, the "summary" must be no more than 70-75
characters, and it must describe both what the patch changes, as well
as why the patch might be necessary.  It is challenging to be both
succinct and descriptive, but that is what a well-written summary
should do.

That said, it seems like kernel maintainers do indeed try to keep things around 50. Here's a histogram of the lengths of the summary lines in the git log for the kernel:

(view full-sized)

There is a smattering of commits that have summary lines that are longer (some much longer) than this plot can hold without making the interesting part look like one single line. (There's probably some fancy statistical technique for incorporating that data here but oh well... :) ).

If you want to see the raw lengths:

cd /path/to/repo
git shortlog  | grep -e '^      ' | sed 's/[[:space:]]\+\(.*\)$/\1/' | awk '{print length($0)}'

or a text-based histogram:

cd /path/to/repo
git shortlog  | grep -e '^      ' | sed 's/[[:space:]]\+\(.*\)$/\1/' | awk '{lens[length($0)]++;} END {for (len in lens) print len, lens[len] }' | sort -n

这篇关于Git提交消息:50/72格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆