Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print git commits body lines joined in one line

How can I print git commits to print only body (commit message without title) but in one line? So commit body lines are joined, possibly separated with space, and printed as one line for one commit.

For example, with two commits A and B, command:

$ git log --format=%b

prints:

Commit A, line A.1
Commit A, line A.2
Commit B, line B.1
Commit B, line B.2

But I'd like to get:

Commit A, line A.1 Commit A, line A.2
Commit B, line B.1 Commit B, line B.2
like image 211
foka Avatar asked Mar 28 '18 15:03

foka


1 Answers

git rev-list master |
    while read sha1; do
        git show -s --format='%B' $sha1 | tr -d '\n'; echo
    done

Let me explain:

git rev-list master

List SHA1 IDs of commits in the branch.

    while read sha1; do

Run a loop over every SHA1.

        git show -s --format='%B' $sha1

Show the body of the commit.

        tr -d '\n'

Remove all line endings.

        echo

Add one newline at the end.

like image 151
phd Avatar answered Oct 16 '22 03:10

phd