带有tformat的git日志中的额外换行符 [英] Extra newline in git log with tformat
问题描述
当我使用 git log --pretty = oneline --shortstat
时,我得到了日志的紧凑表示形式:
When I use git log --pretty=oneline --shortstat
, I get a compact representation of my log:
% git log --pretty=oneline --shortstat
73c6eecd930c2f66d5c1e87fcca7ca9b0e356809 doing stuff with things
3 files changed, 134 insertions(+)
65b457d2e0e94e628e1b30204075540524c8a1d2 doing things with stuff
2 files changed, 4 insertions(+), 1 deletion(-)
...
375531279297af3c787855b0848b400f1c40b638 things with stuff doing
1 file changed, 2 insertions(+)
5501964b19815a07b64e1cd391e032147af33b8f with things doing stuff
25 files changed, 6746 insertions(+)
但是,如果我尝试使用等价于 oneline
的 tformat
,我会在统计信息之前得到一个额外的换行符:
But if I try to use the tformat
equivalent of oneline
, I get an extra newline before the stat:
% git log --pretty="%C(yellow)%H%Creset %s" --shortstat
73c6eecd930c2f66d5c1e87fcca7ca9b0e356809 doing stuff with things
3 files changed, 134 insertions(+)
65b457d2e0e94e628e1b30204075540524c8a1d2 doing things with stuff
2 files changed, 4 insertions(+), 1 deletion(-)
...
375531279297af3c787855b0848b400f1c40b638 things with stuff doing
1 file changed, 2 insertions(+)
5501964b19815a07b64e1cd391e032147af33b8f with things doing stuff
25 files changed, 6746 insertions(+)
没有-shortstat
标志(或-stat
)标志,这两个命令的输出是相同的,因此要添加这些标志.
Without the --shortstat
flag (or --stat
) flag, the output of the two commands is identical, so it's something about adding those flags.
我可以使用grep解决此问题:
I can fix this with grep:
[alias]
x-skip-empty-lines="!f(){ git $* --color=always | grep -vE '^(\\|{0,1}|\\e\\[[^m]*m)[[:space:]]*$' | less ;}; f"
logpatch= !git x-skip-empty-lines log --pretty='%C(yellow)%H%Creset %s' --shortstat
但是有一种方法可以避免首先产生换行符吗?
But is there a way to avoid producing the newline in the first place?
(git 1.8.3和2.0.1)
(git 1.8.3 and 2.0.1)
推荐答案
恐怕您对此无能为力.在 log-tree.c 中,git具有特殊的单行格式的大小写,并且如果不使用它,总是在 shortstat
之前输出两个空行.
I'm afraid that there's nothing you can do about that. In log-tree.c, git has a special case for the oneline format, and always outputs two blank lines before the shortstat
if it is not used.
(我尝试不使用突出显示的行来编译git-log-原始的-pretty = oneline
命令然后还输出两条空行)
(I've tried to compile git-log without the highlighted line - the original --pretty=oneline
command then also outputs two blank lines)
这篇关于带有tformat的git日志中的额外换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!