Thread (1 message) 1 message, 1 author, 2025-08-13

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

From: Junio C Hamano <hidden>
Date: 2025-08-13 14:42:39

Дилян Палаузов [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help