Git log pretty format, newline after placeholder if non-empty

一曲冷凌霜 提交于 2019-12-21 04:39:10

问题


I've got a git alias for a log using the pretty format:

lg = log -10 --graph --abbrev-commit --pretty=format:'%C(auto)%d%Creset%n %C(bold yellow)%h%Creset - %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

Which gives the following:

I can't seem to find a way to make a new line after the reference names only if the placeholder is non-empty.

The pretty formats wiki page has operators to add or remove (+ or -) the newline coming before the placeholder but not after.


回答1:


This is not supported natively by Git: you would have to process/parse the output to get the right result)

But this could also be the opportunity for a simple patch, much like the one which originally introduced the Pretty-format: %[+-]x mechanism: commit 9fa708d, git 1.6.6-rc1, Oct. 2009.

Maybe %[*/]x, for adding line-feed after the expansion of %x.



来源:https://stackoverflow.com/questions/34829747/git-log-pretty-format-newline-after-placeholder-if-non-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!