Skip to contentSkip to conversation

Missing trailing newline with git log --pretty=format

DISCUSSION Andreas Gruenbacher 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

Andreas Gruenbacher, 18.03.2009:

Quoted 8 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:

Quoted 5 lines
	$ 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

#2 lore raw
Quoted 1 line · 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 ;)

Quoted 3 lines

Or better for a script use

	$ git rev-list HEAD^^..HEAD

Much better, thanks.

Andreas

#3 lore raw
Quoted 5 lines · Andreas Gruenbacher
Quoted 1 line · 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.