2016-11-29 65 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