Print git commits body lines joined in one line

谁说胖子不能爱 提交于 2019-11-28 08:38:28

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/49538665/print-git-commits-body-lines-joined-in-one-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!