gitgit-commitcommit-message

What is the best practice for writing long commit messages so that they will be displayed correctly?


I usually write long commit messages in my git bash so that later some one reading my code could easily see what I done. For example in VS 2013 in Windows form application when designing a form I wrote following.

git commit -m "Add Name,age ,height,weight and salary labels with corresponding text boxes and more over a Submit Button..."

Problem was when I typed git log --oneline it did not display the whole message and chopped off a part of it.

What is the way to write long commit messages in Git? What is the limit and how to display them so that all message could easily be seen on git bash?


Solution

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