简体   繁体   English

如何使用git log pretty格式抑制空白行?

[英]How to suppress blank lines with git log pretty format?

I am trying to extend the git log --oneline format to show a little more information, specifically the committer and commit time. 我正在尝试扩展git log --oneline格式以显示更多信息,特别是提交者和提交时间。

The original command is git log --oneline --name-status and produces this output: 原始命令是git log --oneline --name-status并产生以下输出:

[master] ~/temp/tempgit$ git log --oneline --name-status
809d815 (HEAD -> master) modified bar
M       bar.txt
352d6d3 modified foo
M       foo.txt
e4150f4 initial commit
A       bar.txt
A       baz.txt
A       foo.txt

I've duplicated this format with additional information as git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)' and it produces this output: 我已经用其他信息复制了这种格式,例如git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)'并产生以下输出:

[master] ~/temp/tempgit$ git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)'
809d815 (HEAD -> master) modified bar (Mike Harvey, 29 seconds ago)
M       bar.txt

352d6d3 modified foo (Mike Harvey, 49 seconds ago)
M       foo.txt

e4150f4 initial commit (Mike Harvey, 2 minutes ago)
A       bar.txt
A       baz.txt
A       foo.txt

What I want to do is suppress the blank lines between log entries, but cannot find an option to remove it, nor why it is being inserted. 我想做的是消除日志条目之间的空白行,但是找不到删除它的选项,也找不到为什么要插入它。 The only difference here is that I am using a pretty format. 唯一的区别是我使用的是漂亮的格式。

UPDATE: It seems there is no workaround, so I adapted Kjele's solution. 更新:似乎没有解决方法,因此我采用了Kjele的解决方案。 Piping the output loses the color info, which I really wanted, so I forced it with -c color.ui=always. 输配输出会丢失我真正想要的颜色信息,因此我使用-c color.ui = always强制进行了输出。

This is the final version that does what I wanted: 这是完成我想要的工作的最终版本:

git log ${REV}..HEAD --oneline --name-status -c color.ui=always --pretty=format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr) | sed '/^\\s*$/d'

Thanks! 谢谢!

You could pipe your command into: 您可以将命令传递到:

sed '/^\s*$/d'

git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)' |  sed '/^\s*$/d'

but this will not allow you to scroll down like you normally would. 但这不允许您像往常一样向下滚动。

A workaround could be to select the desired number of commits: 一种解决方法是选择所需的提交数量:

-n 10

git log --oneline --name-status --pretty='format:%C(yellow)%h %C(auto)%d %s %C(red)(%cn, %cr)' -n 10 |  sed '/^\s*$/d'

I also found that sed '/^$/d' works as well. 我还发现sed'/ ^ $ / d'也可以。 See tldp tldp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM