Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Commit Messages: 50/72 Formatting

Tags:

git

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 angles 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.)

like image 910
David J. Avatar asked Feb 18 '10 16:02

David J.


People also ask

How detailed should commit messages be?

A good commit message should be two things: meaningful and concise. It should not contain every single detail, describing each changed line—we can see all the changes in Git—but, at the same time, it should say enough to avoid ambiguity.

Is there a limit to git commit messages?

Git Commit Message StructureThe commit message title is limited to 72 characters, and the description has no character limit. While those are the established character limits, most developers suggest that the commit message summary be no longer than 50 characters, and the description be limited to 72.

How long should git commit messages be?

Length: The first line should ideally be no longer than 50 characters, and the body should be restricted to 72 characters. Content: Be direct, try to eliminate filler words and phrases in these sentences (examples: though, maybe, I think, kind of).


2 Answers

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 
like image 73
mgalgs Avatar answered Oct 16 '22 17:10

mgalgs


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.

like image 32
leonbloy Avatar answered Oct 16 '22 18:10

leonbloy