From: Lukas Tenbrink <lukastenbrink@gmail.com>
To: git@vger.kernel.org
Subject: Re: git diff -U0 header off-by-one error when deleting no lines
Date: Wed, 3 May 2023 23:26:17 +0200 [thread overview]
Message-ID: <7F1955DC-0296-470F-96F7-7BB96860D4BD@gmail.com> (raw)
In-Reply-To: <xmqqednxp0ys.fsf@gitster.g>
> This might be unintuitive, but it is specified by POSIX.
>
> Open
>
> https://pubs.opengroup.org/onlinepubs/9699919799/
>
> and look for "@@".
>
> "@@-%s+%s@@", <file1 range>, <file2 range>
>
> Each <range> field shall be of the form:
>
> "%1d", <beginning line number>
>
> or:
>
> "%1d,1", <beginning line number>
>
> if the range contains exactly one line, and:
>
> "%1d,%1d", <beginning line number>, <number of lines>
>
> otherwise.
>
> If a range is empty, its beginning line number shall be the
> number of the line just before the range, or 0 if the empty
> range starts the file.
>
> So a patch that adds lines to an empty file would look like
>
> $ diff -U0 /dev/null test1
> --- /dev/null 2023-04-29 22:24:54.395999895 -0700
> +++ test1 2023-05-03 14:02:27.718960038 -0700
> @@ -0,0 +1,3 @@
> +A
> +B
> +C
>
> just as specified. Note "-0,0" that says "there was no line before
> this hunk before this change".
That is indeed fairly unintuitive, but I appreciate the detailed response. I shall adapt my scripts.
Thanks and best wishes,
Lukas
prev parent reply other threads:[~2023-05-03 21:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-03 20:48 git diff -U0 header off-by-one error when deleting no lines Lukas Tenbrink
2023-05-03 21:19 ` Junio C Hamano
2023-05-03 21:26 ` Lukas Tenbrink [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=7F1955DC-0296-470F-96F7-7BB96860D4BD@gmail.com \
--to=lukastenbrink@gmail.com \
--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).