Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing long commit messages in git?

Tags:

git

People also ask

How do I write a longer commit message?

You may not be able to describe a longer change with a single-line comment. So, you need a multi-line commit message for that purpose. -m flag helps add multiple paragraphs in the same Git commit message. You can do this by adding -m flag for more than once within your message.

How long should git commit messages be?

The ideal size of a git commit summary is around 50 characters in length. Analyzing the average length of commit messages in the Linux kernel suggests this number.

Is there a limit to a git commit message?

The maximum lengths of the subject and message body can be configured in the standard Gerrit config file gerrit. config . The defaults are 50 characters for the summary and 72 characters for the description, as recommended by the git tutorial and expanded upon by Tim Pope.


The way git displays log messages is that it will take the 1st line and use that in git log --oneline, and then anything else is displayed when using the normal git log, as long as there's a blank line between the first and second parts:

Add summary line here

An example of how to write long commit messages.
Blah blah blah blah blah.
SKADOOSH!

A standard that a lot of people use it to use the first line as a summary of the changes in the commit, and to keep it at a max of 50 characters in length so that it can fit when using git log --oneline --graph. This is actually the standard that the Linux kernel and git project maintainers themselves use (GitHub promotes it as well).

You might feel that 50 characters is too short though, so another standard that you could use is to keep the summary to a max of 72, 78, or 80 chars.

For the rest of the commit message, keeping the max line length to 72, 78, or 80 chars max can also be helpful, like if you often split your monitor screens with a terminal in one half and a browser or editor in the other half. Many editors have shortcuts that will auto-wrap long lines to a max column length for you.

For example, in Sublime Text, the command is ALT + CMD + q. Vim also has a few shortcuts to do this (gq is one of them), but you need to configure the max line length for it to work. The same goes for Sublime Text.