From: Junio C Hamano <gitster@pobox.com>
To: "Дилян Палаузов" <dilyan.palauzov@aegee.org>
Cc: git@vger.kernel.org
Subject: Re: git diff shows twice “\ No newline at end of file” - no need for repetition
Date: Wed, 13 Aug 2025 07:42:36 -0700 [thread overview]
Message-ID: <xmqq7bz7p9k3.fsf@gitster.g> (raw)
In-Reply-To: <1b0d634286da16f32cd9faf541ee28c811d6c83f.camel@aegee.org> ("Дилян Палаузов"'s message of "Wed, 13 Aug 2025 10:20:13 +0300")
Дилян Палаузов <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
prev parent reply other threads:[~2025-08-13 14:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-13 7:20 git diff shows twice “\ No newline at end of file” - no need for repetition Дилян Палаузов
2025-08-13 13:11 ` Phillip Wood
2025-08-13 14:51 ` Junio C Hamano
2025-08-13 14:42 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq7bz7p9k3.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=dilyan.palauzov@aegee.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).