2017-04-21 75 views
1

是可以運行一些命令,並採取以下git的日誌消息格式化的git log命令

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

我可以單獨使用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/' 
+0

這與我一直在努力'git的日誌--all --AFTER = 「$ DATE 00:00」 --before礦合併=「$ DATE 23:59」--author =「FatGuyLaughing」--format =%B | sed'/^$/d''應該可以做到這一點。謝謝! – FatGuyLaughing

+0

有沒有辦法讓長信息以製表符而不是八個空格開始? – FatGuyLaughing

+0

更具體地說,是否有一種方法可以執行該命令並讓stdout瞭解製表符? – FatGuyLaughing