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
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Aug 13, 2025, 13:11 UTC
Message-ID
<626efd2e-0396-45a3-9a12-29bb8cbfc173@gmail.com>
In-Reply-To
<1b0d634286da16f32cd9faf541ee28c811d6c83f.camel@aegee.org>
On 13/08/2025 08:20, Дилян Палаузов wrote:
> Hello,
> 
> 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.

The "\ No newline at end of file" applies to the line that precedes it. Removing the first instance in your example would mean the the newline at the end of the file had been removed when the line was changed. The output of git matches what GNU diff shows for incomplete lines.

Thanks
Phillip
Show 21 quoted lines
> I am using git 2.50.0.
> 
> 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.
> 
> Greetings
>    Дилян
> 
> $ git diff
> diff --git a/layouts/_partials/docs/toc-show.html b/layouts/_partials/docs/toc-show.html
> index 21122a1..c243ae5 100644
> --- a/layouts/_partials/docs/toc-show.html
> +++ b/layouts/_partials/docs/toc-show.html
> @@ -2,4 +2,4 @@
>     and
>       (default .Site.Params.BookToC .Params.BookToC)
>       (not (eq .TableOfContents "<nav id=\"TableOfContents\"></nav>"))
> -) }}
> \ No newline at end of file
> +}}
> \ No newline at end of file
> 
Previous: Дилян ПалаузовNext: Junio C Hamano
Message 2 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.