Git 提交消息:50/72 格式

发布于 2024-08-22 05:36:28 字数 1698 浏览 22 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

相守太难 2024-08-29 05:36:28

关于“摘要”行(公式中的 50),Linux 内核文档 有话要说

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.

也就是说,似乎内核维护者确实试图将事情保持在 50 左右。以下是内核 git 日志中摘要行长度的直方图:

Git 摘要行的长度(查看全尺寸

有一些提交的摘要行比该图可以容纳的更长(有些长得多),而不使有趣的部分看起来像一行。 (可能有一些奇特的统计技术可以在这里合并这些数据,但是哦……:-)

如果您想查看原始长度:

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, lens[len] }' | sort -n

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:

Lengths of Git summary lines(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
帅气称霸 2024-08-29 05:36:28

关于“思想领袖”: Linus 强烈提倡完整提交的换行信息:

[…] 我们使用 72 个字符的列进行自动换行,引号除外
具有特定线条格式的材料。

例外主要指“非散文”文本,即不是由人类为提交键入的文本 - 例如,编译器错误消息。

Regarding “thought leaders”: Linus emphatically advocates line wrapping for the full commit message:

[…] we use 72-character columns for word-wrapping, except for quoted
material that has a specific line format.

The exceptions refers mainly to “non-prose” text, that is, text that was not typed by a human for the commit — for example, compiler error messages.

—━☆沉默づ 2024-08-29 05:36:28

演示和数据的分离驱动了我在这里的提交消息。

您的提交消息不应以任何字符数进行硬包装,而应使用换行符来分隔想法、段落等,作为数据的一部分,而不是演示文稿的一部分。在这种情况下,“数据”是您试图传达的消息,“演示”是用户如何看待该消息。

我在顶部使用单个摘要行,并尽量保持简短,但我不会将自己限制为任意数字。如果 Git 实际上提供了一种将摘要消息存储为与消息分开的实体的方法,那就更好了,但由于它不是我必须破解的,并且我使用第一个换行符作为分隔符(幸运的是,许多工具都支持这意味着分解数据)。

对于消息本身,换行符表示数据中有意义的内容。单个换行符表示列表中的开始/中断,双换行符表示新的想法/想法。

This is a summary line, try to keep it short and end with a line break.
This is a thought, perhaps an explanation of what I have done in human readable format.  It may be complex and long consisting of several sentences that describe my work in essay format.  It is not up to me to decide now (at author time) how the user is going to consume this data.

Two line breaks separate these two thoughts.  The user may be reading this on a phone or a wide screen monitor.  Have you ever tried to read 72 character wrapped text on a device that only displays 60 characters across?  It is a truly painful experience.  Also, the opening sentence of this paragraph (assuming essay style format) should be an intro into the paragraph so if a tool chooses it may want to not auto-wrap and let you just see the start of each paragraph.  Again, it is up to the presentation tool not me (a random author at some point in history) to try to force my particular formatting down everyone else's throat.

Just as an example, here is a list of points:
* Point 1.
* Point 2.
* Point 3.

这是软包装文本的查看器中的外观。

这是一个摘要行,尽量保持简短并以换行符结尾。

这是一个想法,也许是对我所做的以人类可读格式的解释。它可能很复杂而且很长,由几个以论文格式描述我的作品的句子组成。现在(在作者时)由我决定用户将如何使用这些数据。

两个换行符将这两个想法分开。用户可能正在手机或宽屏显示器上阅读本文。您是否尝试过在仅显示 60 个字符的设备上阅读 72 个字符换行的文本?这是一次真正痛苦的经历。另外,本段落的开头句(假设论文风格格式)应该是段落的介绍,因此如果工具选择它可能不希望自动换行,而让您只看到每个段落的开头。再说一遍,这取决于演示工具,而不是我(历史上某个时刻的随机作者)试图将我的特定格式强行灌输给其他人。

作为一个例子,这里有一个要点列表:
* 第 1 点。
* 第 2 点。
* 第 3 点。

我怀疑您链接的 Git 提交消息推荐的作者从未编写过可以被不同设备上的广泛最终用户使用的软件(即网站),因为在发展的这一点上在软件/计算领域,众所周知,就用户体验而言,用硬编码的表示信息存储数据是一个坏主意。

Separation of presentation and data drives my commit messages here.

Your commit message should not be hard-wrapped at any character count and instead line breaks should be used to separate thoughts, paragraphs, etc. as part of the data, not the presentation. In this case, the "data" is the message you are trying to get across and the "presentation" is how the user sees that.

I use a single summary line at the top and I try to keep it short but I don't limit myself to an arbitrary number. It would be far better if Git actually provided a way to store summary messages as a separate entity from the message but since it doesn't I have to hack one in and I use the first line break as the delimiter (luckily, many tools support this means of breaking apart the data).

For the message itself newlines indicate something meaningful in the data. A single newline indicates a start/break in a list and a double newline indicates a new thought/idea.

This is a summary line, try to keep it short and end with a line break.
This is a thought, perhaps an explanation of what I have done in human readable format.  It may be complex and long consisting of several sentences that describe my work in essay format.  It is not up to me to decide now (at author time) how the user is going to consume this data.

Two line breaks separate these two thoughts.  The user may be reading this on a phone or a wide screen monitor.  Have you ever tried to read 72 character wrapped text on a device that only displays 60 characters across?  It is a truly painful experience.  Also, the opening sentence of this paragraph (assuming essay style format) should be an intro into the paragraph so if a tool chooses it may want to not auto-wrap and let you just see the start of each paragraph.  Again, it is up to the presentation tool not me (a random author at some point in history) to try to force my particular formatting down everyone else's throat.

Just as an example, here is a list of points:
* Point 1.
* Point 2.
* Point 3.

Here's what it looks like in a viewer that soft wraps the text.

This is a summary line, try to keep it short and end with a line break.

This is a thought, perhaps an explanation of what I have done in human readable format. It may be complex and long consisting of several sentences that describe my work in essay format. It is not up to me to decide now (at author time) how the user is going to consume this data.

Two line breaks separate these two thoughts. The user may be reading this on a phone or a wide screen monitor. Have you ever tried to read 72 character wrapped text on a device that only displays 60 characters across? It is a truly painful experience. Also, the opening sentence of this paragraph (assuming essay style format) should be an intro into the paragraph so if a tool chooses it may want to not auto-wrap and let you just see the start of each paragraph. Again, it is up to the presentation tool not me (a random author at some point in history) to try to force my particular formatting down everyone else's throat.

Just as an example, here is a list of points:
* Point 1.
* Point 2.
* Point 3.

My suspicion is that the author of Git commit message recommendation you linked has never written software that will be consumed by a wide array of end-users on different devices before (i.e., a website) since at this point in the evolution of software/computing it is well known that storing your data with hard-coded presentation information is a bad idea as far as user experience goes.

樱花落人离去 2024-08-29 05:36:28

推荐的最大标题长度真的是 50 吗?

我多年来一直相信这一点,但正如我刚刚注意到“git commit”的文档实际上指出的那样,

$ git help commit | grep -C 1 50
      Though not required, it’s a good idea to begin the commit message with
      a single short (less than 50 character) line summarizing the change,
      followed by a blank line and then a more thorough description. The text

$  git version
git version 2.11.0

人们可能会说“少于 50”只能意味着“不超过 49”。

Is the maximum recommended title length really 50?

I have believed this for years, but as I just noticed the documentation of "git commit" actually states

$ git help commit | grep -C 1 50
      Though not required, it’s a good idea to begin the commit message with
      a single short (less than 50 character) line summarizing the change,
      followed by a blank line and then a more thorough description. The text

$  git version
git version 2.11.0

One could argue that "less then 50" can only mean "no longer than 49".

我还不会笑 2024-08-29 05:36:28

我同意提出一种特定的工作方式很有趣。然而,除非我有机会设定风格,否则我通常会遵循已完成的内容以保持一致性。

看一下 Linux 内核提交,如果您愿意的话,该项目启动了 git,http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=bca476139d2ded86be146dae09b06e22548b67 f3,他们不遵循 50/72 规则。第一行有 54 个字符。

我想说一致性很重要。设置正确的方法来识别已提交的用户(user.name、user.email - 尤其是在内部网络上。User@OFFICE-1-PC-10293982811111 不是有用的联系地址)。根据项目的不同,在提交中提供适当的详细信息。很难说那应该是什么;它可能是开发过程中完成的任务,然后是更改的详细信息。

我不认为用户应该以一种方式使用 git,因为 git 的某些接口以某些方式处理提交。

我还应该注意到还有其他方法来查找提交。首先,git diff 会告诉您发生了什么变化。您还可以执行诸如 git log --pretty=format:'%T %cN %ce' 之类的操作来格式化 git log 的选项。

I'd agree it is interesting to propose a particular style of working. However, unless I have the chance to set the style, I usually follow what's been done for consistency.

Taking a look at the Linux Kernel Commits, the project that started git if you like, http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=bca476139d2ded86be146dae09b06e22548b67f3, they don't follow the 50/72 rule. The first line is 54 characters.

I would say consistency matters. Set up proper means of identifying users who've made commits (user.name, user.email - especially on internal networks. User@OFFICE-1-PC-10293982811111 isn't a useful contact address). Depending on the project, make the appropriate detail available in the commit. It's hard to say what that should be; it might be tasks completed in a development process, then details of what's changed.

I don't believe users should use git one way because certain interfaces to git treat the commits in certain ways.

I should also note there are other ways to find commits. For a start, git diff will tell you what's changed. You can also do things like git log --pretty=format:'%T %cN %ce' to format the options of git log.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文