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

Re: noeol when redirect git log output to a file

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 22, 2021, 17:20 UTC
Message-ID
<xmqqk0r081en.fsf@gitster.g>
In-Reply-To
<20210222231406.CE72.409509F4@e16-tech.com>
Wang Yugui <wangyugui@e16-tech.com> writes:
> [root@T640 ~]# git log '--pretty=format:%h: %an: %s' -- hw/ >a.txt
This is an expected behaviour.

Notice that the format string given above does not end in LF by itself (its final placeholder is the subject string without LF at the end). LF you'd see in the output all come from the "log" machinery and not from the format string. When the machinery adds LFs, there are "separator" and "terminator" behaviour, the former of which adds a separating LF between each item, while the latter adds a terminating LF after each item.

"--pretty=format" is defined to use a separator semantics that is suited to show multi-line items, each of which ends in LF on its own (think of --pretty=format:"by %an%n%b"). Using terminator behaviour you'd get an useless extra LF at the end for such a format, and separator behaviour lets you avoid it.

"git log --help" and find "tformat", to learn more. --format=<fmt>, instead of --pretty=format:<fmt>, may also help.

Previous: Wang Yugui
Message 2 of 2 in “noeol when redirect git log output to a file”
  1. Wang YuguiFeb 22, 2021
  2. Junio C HamanoFeb 22, 2021

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.