Search code examples
gitgit-commitcommit-message

Why are the suggested line lengths for git commits 50 for summaries and 72 for the body?


There is some variation in the exact numbers but in general there are recommended lengths or maximum lengths for the first and subsequent line lengths of commit messages. The common one seems to be at most 72 characters for a message body with a further suggested limit of 50.

What are the reasons for these or other commonly encountered git commit line limits?

I have heard that the 72 character limit is related to the recommended email width limit of 76 as defined in RFC 2045:

(5) (Soft Line Breaks) The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76 characters long.

There is something about a git function adding 4 characters to the commit message when generating an email, which would require the commit line to be shorter than the email limit. In turn I am aware that the email character limit is related to the ~80 character limit of old terminal systems.

If that does explain the 72 character limit, where does the 50 character one come from? Subject: is only 9 characters so adding that before 50 would only give 59. Maybe we then add the commonly used 7 character abbreviated commit hash ID and a space which gives us 67, still 5 spare characters to go.


Solution

  • The 50 character limit for summaries is not a hard limit. But you should strive to find a good short summary for your commits. So aiming for a maximum of 50 characters is a good practice to achieve this.

    I think the body limit of 72 characters has with the good old 80 character per line limit. The linux kernel coding style among many other projects use this.

    The reason it's 72 and not 80 is because git might add some indentation to the body of a git message, and it will still be 80 or less characters.