389

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

ib.
  • 27,830
  • 11
  • 80
  • 100
David J.
  • 31,569
  • 22
  • 122
  • 174
  • 19
    I just noticed that Github's web interface will warn you if your first line is longer than 50 characters by saying "ProTip: Great commit summaries are 50 characters or less. Place extra information in the extended description." – David J. Jun 01 '14 at 15:22
  • 1
    There's a good summary of the 50/72 reasoning in this answer, including some historical reasoning: https://stackoverflow.com/a/50397345/134044 – NeilG Jun 02 '23 at 01:38

5 Answers5

339

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
ib.
  • 27,830
  • 11
  • 80
  • 100
mgalgs
  • 15,671
  • 11
  • 61
  • 74
  • 30
    How did you generate your histogram, out of curiosity? – anarchivist Aug 17 '12 at 00:11
  • 47
    [matplotlib](http://matplotlib.sourceforge.net/) in python. Something like [this](http://stackoverflow.com/a/5328669/209050) but with the output from one of the commands in my answer instead of the random data. – mgalgs Aug 17 '12 at 04:11
  • 3
    Using GNU AWK: `git shortlog | awk '/^ / {gensub(/[[:space:]]\+\(.*\)$/, "\\1", ""); print length()}'` – Dennis Williamson Dec 08 '13 at 15:42
  • So is the 50 just an arbitrary guide to encourage brevity but the 72 a rule to meet a technical consideration for fitting with git output? – TafT Sep 04 '15 at 10:32
  • 9
    Github will hide commit message text after the 70th character. – Peeter Kokk Jul 18 '16 at 09:21
  • (@Dennis) In any POSIX awk `'{sub(/^[[:space:]]+/,"");print length}'` and for the histogram version in recent gawk you _can_ use `PROC_INFO["sorted_in"]="@ind_num_asc"` and skip the `sort -n` but I wouldn't bother. – dave_thompson_085 Aug 13 '16 at 13:48
  • Using `sort -n` should be replaced with `sort -g` to perform a numeric sort, and get a more consistent result. – david Oct 17 '16 at 08:03
  • 3
    concerning the "fancy statistical technique", you could simple make the last bin e.g. "≥ 100" – Tobias Kienzler Mar 23 '17 at 08:24
  • The link to the file is broken. The file has been moved to [this location](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst) instead. – code_dredd Oct 12 '17 at 06:39
  • 3
    Isn't it fascinating that such logical, mathematical people as the Linux kernel maintainers can write a phrase like "no more than 70-75 characters"? – Fletch May 18 '20 at 05:58
97

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.

ib.
  • 27,830
  • 11
  • 80
  • 100
leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • 35
    +1 for bringing up difference between "prose" and "non-prose". And "except for quoted material that has a specific line format". Excellent rule of thumb. – Alois Mahdal Nov 06 '14 at 15:12
54

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.

Micah Zoltu
  • 6,764
  • 5
  • 44
  • 72
  • 69
    Wow, that commit message is painful to read even on a webpage like SO. I don't need *responsive* commit messages, but something which works well with `tig`, `git log` or `gitk`, and maybe also github. – Benjamin Bannier Aug 20 '13 at 04:07
  • 37
    The message would be easy to read with any viewer that word wraps. I put it in a non-wrapping code block as an example. – Micah Zoltu Aug 20 '13 at 07:41
  • 24
    Thanks for a different perspective. In theory, your answer sounds fine. In practice, I like line breaks for current command line tools. – David J. Aug 21 '13 at 01:44
  • 4
    *"storing your data with hard-coded presentation information"* OK but git messages are not data but meta-data. Also, if "line break after 70 chars" is presentation information, then "two line breaks after thought" or bullet points is what? – Alois Mahdal Nov 06 '14 at 16:55
  • 21
    The character sequence `\n\n` is a thought separator. `\n* ` is a list item indicator. How those are rendered is up to the view. The problem with artificial line breaks is that they are associated with nothing *except* the presentation. There isn't any data-related information being transmitted by putting a line break at 70 characters. My choice of `\n\n` and `\n* ` is the same as why markdown chose it, because it is a form of encoding data that also happens to look somewhat reasonable in a plain text view. – Micah Zoltu Nov 06 '14 at 20:38
  • 6
    "The message would be easy to read with any viewer that word wraps." And difficult to read on a viewer that doesn't. Since some popular viewers (e.g. gitk) don't word-wrap, we'll have to do it ourselves. – Bennett McElwee Jun 15 '15 at 04:14
  • 25
    Hard wraps are difficult to read on devices with small screens (mobile). The message will be difficult to read somewhere no matter what you do. I would rather follow modern best practices than cater to legacy software that doesn't have some of the most basic rendering capabilities. – Micah Zoltu Jun 15 '15 at 14:06
  • 6
    This would contradict the _good email netiquette_ of wrapping anything longer than 80 chars. It is that which probably formed the base of the git format suggestion. Yes other devices could display more characters, but anything that fancy could take a guess at unwrapping if the user wanted. Also some devices might have smaller displays but only few cannot manage 80 chars. The intended audience was a terminal email client, not a mobile browser. You have made some interesting points though and I have long wondered when the 80 char thing could be modernised to a larger value. – TafT Sep 04 '15 at 10:37
  • 13
    "It is up to the presentation tool… not me…" Modern presentation tools, properly written, take into account historical formatting nuances like width constraints, and remove unpaired newlines before re-wrap/display. (Markdown is a great example.) Thus, including breaks at 72 does no harm to such tools, and it has the added benefit of working nicely with less "blessed" toolchains. I understand the desire to ditch practices pushed by old tools, but in my estimation it isn't *that* much extra effort, and it will result in fewer people cursing you behind your back when they're stuck using less. :P – Mark G. Feb 29 '16 at 21:38
  • 2
    I used to do the "hard character count" max, but now I am starting to move away from it. I have started to follow the Asciidoc recommended practice of ["One Sentence Per Line"](http://asciidoctor.org/docs/asciidoc-recommended-practices/#one-sentence-per-line). – mkobit Mar 08 '16 at 17:57
  • 6
    For anybody who uses `git gui`, you can enable word wrap in its commit area by editing `/usr/lib/git-core/git-gui` and changing `-wrap none` to `-wrap word` in the `text $ui_comm ...` definition. – Tobia Jun 30 '16 at 17:15
  • 4
    @TafT _"anything that fancy could take a guess at unwrapping"_ I have yet to find an editor (embedded or standalone) that does unwrapping, even when the editor wraps itself. – jebob Mar 08 '17 at 18:20
  • 3
    A long subject line will be unreadable in email clients. Are they legacy software too now? – LtWorf Jun 12 '17 at 12:32
  • 4
    **I truly, deeply, strongly disagree with this suggestion!** And it's also contradictory. By one hand, the char sequences like `\n\n` and `\n*` are defended for being "markdown-like" while line length is ignored. Well, markdown considers a block of text as a virtual single line that is rendered responsively according to the view-port, while keeping the readability of the plain text version. Also, this approach is not practical. The terminal is *literally* where these messages are going to be read most of the times. Ignoring this obvious reality is a good way to annoy everyone working with you. – Victor Schröder Jul 25 '19 at 20:49
  • 4
    I haven't looked at a git commit message in a terminal for years, I am always viewing them in more advanced tooling. Even within terminal applications, soft wrapping is widely supported these days. While I acknowledge there are still some pieces of legacy software out there in use that don't support soft-wraps, I would argue that we should not constrain ourselves because people refuse to upgrade their software. – Micah Zoltu Jul 26 '19 at 13:53
  • @LtWorf Sorry, just noticed your message (from years ago!) As I mentioned, I try to keep the subject line short but I don't cut it off without finishing the thought. Sometimes the thought is longer than will fit in the subject line of an email on my phone (most thoughts don't fit in that space) and that is OK. On my phone (a modern and large device) I don't believe I can see a 50 character subject line in an email notification, so the 50 character limit isn't likely to help any more in this situation. – Micah Zoltu Jul 26 '19 at 13:55
  • 1
    What about separation between the summary and the first thought? This is recommended by [the documentation for `git commit`](https://git-scm.com/docs/git-commit#_discussion), and is relevant in places like `git log --oneline`. – jirassimok Dec 14 '19 at 19:11
  • 1
    To clarify, the documentation recommends using a blank line to separate the summary and description (along with short summaries, this is its only recommendation). `git log`, other `git` commands, and some UIs treat the series of non-blank lines as the summary, though other UIs (e.g. GitHub) do not. – jirassimok Dec 14 '19 at 19:27
  • 1
    Since writing this, my personal style has shifted to a blank line between summary and first thought. I find it reads a bit cleaner that way when printed unformatted. – Micah Zoltu Dec 15 '19 at 23:35
  • 2
    I would upvote this several times if I could. Preformatting for a specific historic line length is bad. – A. Donda Dec 31 '19 at 04:03
  • 1
    @MarkG. "Modern presentation tools, properly written, ... remove unpaired newlines before re-wrap/display. (Markdown is a great example.)" Unfortunately GitHub doesn't do that, so when I wrap commit messages and open a PR, I have to manually remove new line characters to get it to wrap normally. – Nateowami Apr 24 '20 at 22:59
  • 1
    "I haven't looked at a git commit message in a terminal for years, I am always viewing them in more advanced tooling." I'm different. More often than not I'm working on the CLI or ssh'ing into a build/test/CI server, and I need to look at logs that way. Faster via `git log` than sftp'ing things or invoking a local GUI tool. I only use advance tooling for more complicated things (a 3-way-merge or comparing logs among branches.) – luis.espinal Jan 25 '22 at 16:48
  • 1
    this so much. word wrapping a paragraph is a presentation issue. we shouldn't be baking our assumptions about the way the message will be displayed _into_ the message. – Dave Cousineau May 18 '22 at 18:23
  • says doesn't want to "force formatting down anyone's throat" while forcing long lines down everyone's throat. It's the same as atheists pretending they're different from anyone else as if they haven't got their own set of origins beliefs. – NeilG Jun 02 '23 at 01:32
  • I *always* use a terminal for my work with Git and other tools. I don't know why people who don't use terminals think they're using "more advanced" tools. They're usually the opposite: dumbed down versions with point and click alternatives to the powerful terminal scripting environment. I don't have problems with long lines in the terminal. I'm usually the one pushing for longer line lengths in the code. I don't have problems with 50/72 either and usually conform, although I'm sometimes over 50 on the first line by a few characters because sometimes that's too hard. – NeilG Jun 02 '23 at 01:56
13

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".

6

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.

  • For reference he says "As the example indicates, you should shoot for about 50 characters (though this isn’t a hard maximum)", but I suppose you have a point in that you shouldn't have to work around your tools. – Omni5cience Feb 23 '11 at 00:13