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 sim
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'
Personal suggestion is be simple. When you want to see the full lines in the less pager just type -S this will change to folding the lines or back should you wish to view a section that way.
SHORT ANSWER:
Type -S
then Enter when viewing the git log.
DETAILED ANSWER:
git log
outputs using the less
text viewer, so simply type -S
then Enter to toggle between the two line-wrapping modes of "Chop long lines" and "Fold long lines." The "Fold long lines" option enables word wrap.
Source that helped me learn this: https://superuser.com/a/272826/425838
If nano is your preferred editor, then you can set up git to use nano with automatic wrapping at e.g. 72 characters:
git config --global core.editor "nano -r 72"
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).
This is how I solved for wrapping git log messages, for those who are still looking for answers:
git log --pretty=format:"@%H,%cn,%cD,%B" <file name> | tr "\n" " "|tr "@" "\n"
The output of the git log command is piped that finds the newline and replaces with a white space. This is the logic used to join commit messages as a single line.
Here, I am using "@" as a delimiter to differentiate between the commits. You can replace it with whatever special symbol you want. "%H" represents commit hash, "%cn" represents committer name, "%cD" represents commit date, and "%B" raw body message. If you want to know more about pretty=format, please take a look at https://git-scm.com/docs/pretty-formats
Please note that this may not work if you have newline character within git commit message.