gpt4 book ai didi

git - 带有 tformat 的 git log 中的额外换行符

转载 作者:太空狗 更新时间:2023-10-29 13:35:50 25 4
gpt4 key购买 nike

当我使用 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)

最佳答案

恐怕您对此无能为力。在 log-tree.c , git 对 oneline 格式有一个特例,如果不使用它,总是在 shortstat 之前输出两个空行。

(我试过在没有高亮行的情况下编译 git-log - 原始的 --pretty=oneline 命令然后也输出两个空行)

关于git - 带有 tformat 的 git log 中的额外换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25630021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com