Issue
I want to use git log
in a project to view only the commits that have more than one line in their commit messages (i.e. they have a longer description). What is the best way to go about this?
I tried git log --grep='\n\n'
, and it came up with a list of commits with more than one line, but it was not a complete list. (I went back through some of the complete log manually and quickly found commits with multiline messages that were not output by my command.)
I then also tried git log --grep='\n\r\?\n'
, just in case there are Windows-style line endings in some of the commits (I'm using msysgit
, so it might be possible?), but it came up with the same output as the above.
Solution
This seems to work for me (on Linux):
git log --pretty=format:'%H<msgst>%b<msge>' \
| fgrep -v '<msgst><msge>' | fgrep '<msgst>' | cut -b1-40 \
| git log --stdin --no-walk
Basically: print commit hashes and commit message body (minus the subject line) wrapped in some uncommon strings, exclude lines where such body is empty (e.g. commits without newlines in the messages), then take just the first lines (those with commit hash at the beginning), and print only the hashes.
Answered By - che Answer Checked By - Cary Denson (WPSolving Admin)