1

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.

1 Answer 1

1

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/'
Sign up to request clarification or add additional context in comments.

8 Comments

This combined with mine that I have been working on git log --all --after="$DATE 00:00" --before="$DATE 23:59" --author="FatGuyLaughing" --format=%B | sed '/^$/d' should do the trick. Thank you!
Is there a way to make the long message start with tab character instead of the eight spaces?
More specifically is there a way to take that command and have stdout understand tab characters?
@FatGuyLaughing I think git doesn't use tabs, but you could replace trailing spaces, i.e. | sed 's/^ /\t/'.
This just added the letter t to the beginning of the 8 spaces created by git. Also, having a hard time finding out whether or not stdout can handle tab characters.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.