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

Re: git diff shows twice “\ No newline at end of file” - no need for repetition

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 13, 2025, 14:42 UTC
Message-ID
<xmqq7bz7p9k3.fsf@gitster.g>
In-Reply-To
<1b0d634286da16f32cd9faf541ee28c811d6c83f.camel@aegee.org>
Дилян Палаузов <dilyan.palauzov@aegee.org> writes:
> Hello,
[jc: please wrap long lines]
> when a file, which does not end in a new line, is modified, git
> diff shows twice the text “\ No newline at end of file”. As this
> piece of the file is not modified, I think git diff should print
> it once.

Perhaps "this piece of the file" is indeed modified. In your example, the file before the change had a line with ") }}" on it without terminating newline at the end, and this piece of the file is changed to a line with "}}" on it without terminating newline. The first "\ No newline" belongs to (is a part of) the file before the change and annotates something peculiar about that line, and the second "\ No newline" belongs to (is a part of) the file after the change. If the line were complete before your change and you made it incomplete while removing ") ", then the first "\ No newline" would not have been in the output. If you fixed the incomplete line at the end of file by adding a newline at the end while you removing ") ", then the second "\ No newline" would not have been in the output. But in this case, I think you had it incomplete before the change, and you did not fix it and the incompleteness of the line remained after the change, so "diff" should mark both line before and after the change incomplete with "\ No newline" marker.

> -) }}
> \ No newline at end of file
> +}}
> \ No newline at end of file
Previous: Junio C Hamano
Message 4 of 4 in “git diff shows twice “\ No newline at end of file” - no need for repetition”
  1. Дилян ПалаузовAug 13, 2025
  2. Phillip WoodAug 13, 2025
  3. Junio C HamanoAug 13, 2025
  4. Junio C HamanoAug 13, 2025

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.