FatGuyLaughing
FatGuyLaughing

Reputation: 215

Formatting git log command

Is is possible to run some command and take the following git log message

commit 55dbd23f3802527cef5f9d3d5ea4dd3c69c72c5a
Author: Example User
Date:   Thu Apr 20 15:40:15 2017 -0500

    Here is the short commit message line.

    Here is the long commit message.
    This message can span multiple lines or have line breaks.

    Some more information about this commit.

and output it like the following.

Here is the short commit message line.
    Here is the long commit message.
    This message can span multiple lines or have line breaks.
    Some more information about this commit.

So if I have another commit following it that is just a one line commit message then I would like the output to look like.

Here is the short commit message line.
    Here is the long commit message.
    This message can span multiple lines or have line breaks.
    Some more information about this commit.
A different commit was made here. This only uses short message.

Upvotes: 1

Views: 1036

Answers (1)

kan
kan

Reputation: 28951

The best I could do with git format alone is this:

git log --pretty="format:%s%w(0,8,8)%+b"

It puts the subject and then the padded body. However, as I understand git cannot modify body text, so all blank lines inside the body remain as is. So you could filter them out e.g. by using grep

git log --pretty="format:%s%w(0,8,8)%+b" | grep -v '^ *$'

Replace with tabs:

git log --pretty="format:%s%w(0,1,1)%+b" | grep -v '^ *$' | sed 's/^ /\t/'

Upvotes: 1

Related Questions