threads / discuss / 18386

Missing trailing newline with git log --pretty=format

Subject: Missing trailing newline with git log --pretty=format

## tl;dr

4 messages between Mar 18, 2009 and Mar 18, 2009.

replies: 3people: 3as markdown or json

Andreas Gruenbacher· Mar 18, 2009, 21:23 UTC · lore
Hello,
with the latest version of git from right now (e986ceb):

While trying to get a reverse list of commit ids, I noticed that git log prints newlines between commits, but not at the end. This results in two joined lines with:

	$ git log --pretty=format:%h HEAD^^..HEAD | tac
	aab3b9a7d4e3a7
	e986ceb
Any chance of getting this fixed?

Thanks, Andreas

Markus Heidelberg· Mar 18, 2009, 21:56 UTC · re: Andreas Gruenbacher · lore

Re: Missing trailing newline with git log --pretty=format

Andreas Gruenbacher, 18.03.2009:
Show 13 quoted lines
> Hello,
> 
> with the latest version of git from right now (e986ceb):
> 
> While trying to get a reverse list of commit ids, I noticed that git log 
> prints newlines between commits, but not at the end. This results in two 
> joined lines with:
> 
> 	$ git log --pretty=format:%h HEAD^^..HEAD | tac
> 	aab3b9a7d4e3a7
> 	e986ceb
> 
> Any chance of getting this fixed?
Use tformat instead of format. Or better for a script use
	$ git rev-list HEAD^^..HEAD

But somehow --abbrev or --abbrev-commit don't work. Am I doing something wrong?

Markus
Andreas Gruenbacher· Mar 18, 2009, 22:04 UTC · re: Markus Heidelberg · lore

Re: Missing trailing newline with git log --pretty=format

On Wednesday, 18 March 2009 22:56:43 Markus Heidelberg wrote:
> Use tformat instead of format.

Hmm ... didn't know that, thanks. Now I wonder why anyone would ever want format instead of tformat ;)

> Or better for a script use 
>
> 	$ git rev-list HEAD^^..HEAD
Much better, thanks.
Andreas
Junio C Hamano· Mar 18, 2009, 22:27 UTC · re: Andreas Gruenbacher · lore

Re: Missing trailing newline with git log --pretty=format

Andreas Gruenbacher <agruen@suse.de> writes:
Show 5 quoted lines
> On Wednesday, 18 March 2009 22:56:43 Markus Heidelberg wrote:
>> Use tformat instead of format.
>
> Hmm ... didn't know that, thanks. Now I wonder why anyone would ever want 
> format instead of tformat ;)

If your payload is multi-line, you would want to see a separating empty line in between entries, but not after the last one:

	$ command with --format
        The first line of first entry.
        The second line of first entry.
        ...
        The last line of first entry.
        The first line of second entry.
        ...
        ...
        The last line of last entry.
        $ notice there is no extra newline after that

That is what --format does. One-line-per-entry is a special case. You do not want a "separating LF in between entries", but a "terminating LF after each entry". T in --tformat stands for this "terminating" aspect, as opposed to the "separator" behaviour --format gives you.

← back to recent threads