{"thread":{"id":"63951","subject":"git diff shows twice “\\ No newline at end of file” - no need for repetition","startedAt":"2025-08-13T07:28:46Z","lastAt":"2025-08-13T14:51:11Z","messageCount":4,"participants":["Дилян Палаузов","Phillip Wood","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"524115","messageId":"1b0d634286da16f32cd9faf541ee28c811d6c83f.camel@aegee.org","threadId":"63951","inReplyTo":null,"subject":"git diff shows twice “\\ No newline at end of file” - no need for repetition","fromName":"Дилян Палаузов","fromEmail":"dilyan.palauzov@aegee.org","sentAt":"2025-08-13T07:20:13Z","receivedAt":"2025-08-13T07:28:46Z","isPatch":false,"sender":{"key":"dilyan.palauzov@aegee.org","avatar":null},"body":"Hello,\n\nwhen 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.  In the example below the first “\\ No newline at end of file” should be skipped.\n\nI am using git 2.50.0.\n\nAs a matter of fact github also shows this information twice - https://github.com/alex-shpak/hugo-book/pull/755/files - which I find is bad.\n\nGreetings\n  Дилян\n\n$ git diff \ndiff --git a/layouts/_partials/docs/toc-show.html b/layouts/_partials/docs/toc-show.html\nindex 21122a1..c243ae5 100644\n--- a/layouts/_partials/docs/toc-show.html\n+++ b/layouts/_partials/docs/toc-show.html\n@@ -2,4 +2,4 @@\n   and\n     (default .Site.Params.BookToC .Params.BookToC)\n     (not (eq .TableOfContents \"<nav id=\\\"TableOfContents\\\"></nav>\"))\n-) }}\n\\ No newline at end of file\n+}}\n\\ No newline at end of file\n"},{"id":"524121","messageId":"626efd2e-0396-45a3-9a12-29bb8cbfc173@gmail.com","threadId":"63951","inReplyTo":"1b0d634286da16f32cd9faf541ee28c811d6c83f.camel@aegee.org","subject":"Re: git diff shows twice “\\ No newline at end of file” - no need for repetition","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-08-13T13:11:55Z","receivedAt":"2025-08-13T13:12:00Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 13/08/2025 08:20, Дилян Палаузов wrote:\n> Hello,\n> \n> 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.  In the example below the first “\\ No newline at end of file” should be skipped.\n\nThe \"\\ No newline at end of file\" applies to the line that precedes it. \nRemoving the first instance in your example would mean the the newline \nat the end of the file had been removed when the line was changed. The \noutput of git matches what GNU diff shows for incomplete lines.\n\nThanks\n\nPhillip\n\n\n> I am using git 2.50.0.\n> \n> As a matter of fact github also shows this information twice - https://github.com/alex-shpak/hugo-book/pull/755/files - which I find is bad.\n> \n> Greetings\n>    Дилян\n> \n> $ git diff\n> diff --git a/layouts/_partials/docs/toc-show.html b/layouts/_partials/docs/toc-show.html\n> index 21122a1..c243ae5 100644\n> --- a/layouts/_partials/docs/toc-show.html\n> +++ b/layouts/_partials/docs/toc-show.html\n> @@ -2,4 +2,4 @@\n>     and\n>       (default .Site.Params.BookToC .Params.BookToC)\n>       (not (eq .TableOfContents \"<nav id=\\\"TableOfContents\\\"></nav>\"))\n> -) }}\n> \\ No newline at end of file\n> +}}\n> \\ No newline at end of file\n> \n\n"},{"id":"524128","messageId":"xmqq7bz7p9k3.fsf@gitster.g","threadId":"63951","inReplyTo":"1b0d634286da16f32cd9faf541ee28c811d6c83f.camel@aegee.org","subject":"Re: git diff shows twice “\\ No newline at end of file” - no need for repetition","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-13T14:42:36Z","receivedAt":"2025-08-13T14:42:39Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Дилян Палаузов <dilyan.palauzov@aegee.org> writes:\n\n> Hello,\n\n[jc: please wrap long lines]\n\n> when a file, which does not end in a new line, is modified, git\n> diff shows twice the text “\\ No newline at end of file”. As this\n> piece of the file is not modified, I think git diff should print\n> it once.\n\nPerhaps \"this piece of the file\" is indeed modified.  In your\nexample, the file before the change had a line with \") }}\" on it\nwithout terminating newline at the end, and this piece of the file\nis changed to a line with \"}}\" on it without terminating newline.\nThe first \"\\ No newline\" belongs to (is a part of) the file before\nthe change and annotates something peculiar about that line, and the\nsecond \"\\ No newline\" belongs to (is a part of) the file after the\nchange.  If the line were complete before your change and you made\nit incomplete while removing \") \", then the first \"\\ No newline\"\nwould not have been in the output.  If you fixed the incomplete line\nat the end of file by adding a newline at the end while you removing\n\") \", then the second \"\\ No newline\" would not have been in the\noutput.  But in this case, I think you had it incomplete before the\nchange, and you did not fix it and the incompleteness of the line\nremained after the change, so \"diff\" should mark both line before\nand after the change incomplete with \"\\ No newline\" marker.\n\n> -) }}\n> \\ No newline at end of file\n> +}}\n> \\ No newline at end of file\n"},{"id":"524129","messageId":"xmqqwm77nule.fsf@gitster.g","threadId":"63951","inReplyTo":"626efd2e-0396-45a3-9a12-29bb8cbfc173@gmail.com","subject":"Re: git diff shows twice “\\ No newline at end of file” - no need for repetition","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-08-13T14:51:09Z","receivedAt":"2025-08-13T14:51:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> On 13/08/2025 08:20, Дилян Палаузов wrote:\n>> Hello,\n>> when a file, which does not end in a new line, is modified, git diff\n>> shows twice the text “\\ No newline at end of file”. As this piece\n>> of the file is not modified, I think git diff should print it once.\n>> In the example below the first “\\ No newline at end of file”\n>> should be skipped.\n>\n> The \"\\ No newline at end of file\" applies to the line that precedes\n> it. Removing the first instance in your example would mean the the\n> newline at the end of the file had been removed when the line was\n> changed. The output of git matches what GNU diff shows for incomplete\n> lines.\n>\n> Thanks\n\nThanks for a concise and accurate diagnosis.  It is unfortunate that\nwe cannot point at POSIX X-<.\n"}]}