格式化git log命令

时间:2017-04-21 15:53:39

标签: git

是否可以运行某些命令并采用以下git日志消息

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.

并输出如下。

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.

因此,如果我有另一个提交,它只是一行提交消息,那么我希望输出看起来像。

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 个答案:

答案 0 :(得分:1)

我能用git格式做的最好的就是:

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

它放置主体,然后是衬垫的身体。但是,据我所知,git无法修改正文,因此正文中的所有空行都保持不变。所以你可以过滤它们,例如使用grep

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

替换为标签:

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