2016-11-29 62 views
0

我使用git log來閱讀提交消息,但其中一些超長,包含回溯和其他我不想看到的東西。我希望看到每個提交的正文的前10行。我已經閱讀了git log的文檔(尤其是--format),似乎沒有辦法做到這一點。如何獲取git日誌來限制每個提交消息的行數?

+0

混帳--oneline它減少到ONELINE,你可能會發現此鏈接有用:http://stackoverflow.com/questions/21830810/how-to-make- git-log-cut-long-comments – the12

回答

2

您需要處理每個git日誌條目。

請叫git-logm一個bash腳本(在Windows上運行偶數)與

#!/bin/bash 
for ((i=0; i<=$1; i++)) 
do 
    body=$(git log -1 --skip=$i --pretty=format:%B|head -4) 
    echo "HEAD~$i $body" 
done 

然後,git logm 5將顯示5次提交,每一個僅在第4行的提交信息的。

+0

我在做兩個日期之間的git log,所以我不認爲這對我有用。 – hexdreamer

+0

@hexdreamer當然:你只需要爲這兩個日期之間的每次提交獲取SHA1,然後請求腳本中顯示的提交消息(帶有| head -4') – VonC

+0

似乎是一個迂迴曲折,但我認爲我可以讓它起作用。我會給它一個鏡頭。 – hexdreamer

0

我用這個別名來快速查看我所有的提交,這很方便。將它添加到.bashrc或.zshrc文件中。

alias glo='git log --oneline --decorate' 

樣本輸出:

1417fb7 (HEAD -> master, origin/master) Updated .gitignore 
5a22485 Add sample BG PDF docs 
423131e Fixing the .gitignore file. 
633d7de Added some examples 
ab752e4 Initial commit 
960d841 Create 'Hello World' example to output PDF. 
+0

我想得到這個主題和約10個身體線條,所以我不認爲這對我有用。 – hexdreamer