【问题标题】:Extra newline in git log with tformat带有 tformat 的 git log 中的额外换行符
【发布时间】: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 需要不同的东西,但我想举一个小例子。

标签: git git-log


【解决方案1】:

恐怕你对此无能为力。在log-tree.c中,git对单行格式有一种特殊情况,如果不使用,总是在shortstat之前输出两个空行。

(我尝试在没有突出显示的行的情况下编译 git-log - 原始的 --pretty=oneline 命令也输出两个空行)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    相关资源
    最近更新 更多