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

From: Junio C Hamano <[email-masked]>
Date: Wed, 13 Aug 2025 07:42:36 -0700

Дилян Палаузов <[email-masked]> 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