Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra newline in git log with tformat

Tags:

git

git-log

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(+)

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(+)

Without the --shortstat flag (or --stat) flag, the output of the two commands is identical, so it's something about adding those flags.

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 and 2.0.1)

like image 821
rampion Avatar asked Sep 02 '14 18:09

rampion


1 Answers

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.

(I've tried to compile git-log without the highlighted line - the original --pretty=oneline command then also outputs two blank lines)

like image 124
Phillip Avatar answered Sep 27 '22 19:09

Phillip