【发布时间】:2014-10-27 02:38:35
【问题描述】:
当我使用 git log --pretty=oneline --shortstat 时,我得到了我的日志的紧凑表示:
% 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(+)
但如果我尝试使用 tformat 等效于 oneline,我会在 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)标志,两个命令的输出是相同的,所以需要添加这些标志。
我可以用 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
但是有没有办法一开始就避免产生换行符?
(git 1.8.3 和 2.0.1)
【问题讨论】:
-
tformat equivalent of pretty是什么意思?你的意思是tformat equivalent of pretty=oneline? -
hek2mgl:谢谢,已修复。
-
好的。 :) (不想太挑剔,我只是不确定,似乎需要正确阅读问题才能回答它。而且我不是 git-super-hero)... 返回这个话题,似乎这不等同于
pretty=oneline。 (因为输出不同)你从哪里得到格式表达式? -
hek2mgl:这组标志的等价物(我在我的
~/.gitconfig中设置了color=auto)。--abbrev-commit或--decorate需要不同的东西,但我想举一个小例子。