git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: bug: git format prints no final newline

From
Jeff King <peff@peff.net>
Date
Nov 3, 2022, 04:43 UTC
Message-ID
<Y2NG6u1TVdDBZAZE@coredump.intra.peff.net>
In-Reply-To
<CAKz_xw2X+eapmASqG7V=RXehh7=LN24m+MJPn-wx80oZAZHBnQ@mail.gmail.com>
On Thu, Nov 03, 2022 at 02:14:37PM +1100, Evan Benn wrote:
> This command omits the final newline:
> 
> git log --format=format:"%H"

This is the intended behavior. See the section on "tformat:" in "git help log", and the discussion of "terminator" vs "separator" semantics.

The "separator" semantics are helpful for most multiline formats (where your separator is probably a blank line, and you don't want an extra one at the end). Terminator is more useful for one-line outputs.

I think one could argue that the terminator one is what most people want and would be a better default, but "format" is the way it is for historical compatibility. If you use the do-what-I-mean form of:

  git log --format=%H

then it defaults to tformat (notice no "format:" or "tformat:" keyword; we infer from the presence of "%H" in the name that it's a custom format, and that is what defaults to tformat).

-Peff
Previous: Evan Benn
Message 2 of 2 in “bug: git format prints no final newline”
  1. Evan BennNov 3, 2022
  2. Jeff KingNov 3, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.