How to wrap git commit comments?

Is there a way to wrap git commit comments (when viewed via git log), so they are not cut off at the end of the line? It seems like there should be a pretty simple solution, but I haven't been able to find one.

Thanks.


Or you can change your pager to use less -R

$ git config --global core.pager 'less -R'

This will tell less to stop trying to control how the screen is formatted (you can normally scroll right and left during a git log using arrow keys). And as the less manual says "Thus, various display problems may result, such as long lines being split in the wrong place." Which is what you want, you want the line ending to appear at the right of your screen (the wrong place) instead of where the comment author put it.

Also to note, pressing the right arrow key without modifying your pager, will let you see more of the code. Which is my preferred method.


Edit 2011: the other answers (upvoted) highlight the possibility to modify the options less, the default pager used by git.
The remark at the end of my answer still stands: even if you can see long commit message, that doesn't means that other tools having to deal with said (long) message will be able to process them.


Original answer (January 2010) about commit message format policy:

According to this blog, since git log does not do any kind of wrapping, you need to format your comment with an appropriate line length

  • git log doesn't do any special special wrapping of the commit messages.
    With the default pager of less -S, this means your paragraphs flow far off the edge of the screen, making them difficult to read.
    On an 80 column terminal, if we subtract 4 columns for the indent on the left and 4 more for symmetry on the right, we're left with 72 columns.
  • git format-patch --stdout converts a series of commits to a series of emails, using the messages for the message body.
    Good email netiquette dictates we wrap our plain text emails such that there's room for a few levels of nested reply indicators without overflow in an 80 column terminal.

As said here:

In general, use an editor to create your commit messages rather than passing them on the command line. The format should be:

  • A hard wrap at 72 characters
  • A single, short, summary of the commit
  • Followed by a single blank line
  • Followed by supporting details

All sources (including GitPro book, which goes for 50 characters for the first line, as Jörg W Mittag comments) insist on the necessity to wrap yourself the comment, certainly because, even if Git was able to deal with long lines, other tools in the processing chain (email, patches, ...) may not.


There doesn't seem to be any perfect way. A workaround I use is just to pipe the output to more (or less, or cat etc.):

git log | more

That wraps the long lines at least on my system (however, you miss the color formatting).


Mentioned in the previous answer is that the default pager (often 'less') is responsible for wrapping and by default it generally chops long lines.

To modify this without changing your commit messages (less and bash example):

$ echo $LESS
-FRSX

This was what I had by default, now to overwrite the LESS environment variable.

echo "LESS=-FRX;export LESS" >> ~/.bash_profile
source ~/.bash_profile

Note that less -r (as recommended above) leads to less forgetting its line count and you miss commits because your topmost lines will scroll out of sight! The real fix is disabling the -S option that git enables by default if the LESS environment variable is not set.

A good fix is changing your git config in the following way:

git config --global core.pager 'less -+S'