git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: ZheNing Hu <adlternative@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>, Git List <git@vger.kernel.org>
Subject: Re: [QUESTION] how to diff one blob with nothing
Date: Thu, 3 Aug 2023 11:24:33 -0400	[thread overview]
Message-ID: <ZMvGsYSystLu6oBY@nand.local> (raw)
In-Reply-To: <CAOLTT8S=_1Vd2Y4rBqq03JsJ1megRBcx9v-HYAWXe88jDek98Q@mail.gmail.com>

On Thu, Aug 03, 2023 at 01:16:02PM +0800, ZheNing Hu wrote:
> > Here, it is necessary to compare multiple versions of blobs while also
> > considering the situations of creation and deletion.
> >
> > Well, what I need is the "diff" content, with lines in the diff indicating
> > '+' or '-' signs. This can be achieved by manually adding them, but it is
> > not very compatible with the original logic.
>
> The native diff command itself supports comparison with an empty file.
>
> #diff -u  /dev/null a
> --- /dev/null 2023-07-25 16:47:50.270094301 +0800
> +++ a 2023-08-03 13:14:16.980262362 +0800
> @@ -0,0 +1 @@
> +a
>
> So I believe this feature would also be useful in git.

Sure, you can easily diff any file against any other, including if
either one or both are empty. I think the main difference here is that
/dev/null exists on your system without additional configuration and
the empty blob does not exist in a Git repository without additional
configuration (in this case, `git hash-object -w -t blob --stdin
</dev/null`).

TBH, I don't know if /dev/null existing by default is necessarily a
solid argument in favor of having Git repositories come initialized with
the empty blob by default.

(To be clear, when I say "initialized", I mean that a Git repository
would recognize the empty blob object's hash for any value of
`the_hash_algo`, not that every repository would be prepared with a
loose object by default.)

Thanks,
Taylor

  reply	other threads:[~2023-08-03 15:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19  9:59 [QUESTION] how to diff one blob with nothing ZheNing Hu
2023-07-19 16:15 ` Junio C Hamano
2023-07-26 18:00   ` ZheNing Hu
2023-07-26 18:23     ` Junio C Hamano
2023-07-27 17:46       ` Taylor Blau
2023-07-28  3:40         ` ZheNing Hu
2023-08-03  5:16           ` ZheNing Hu
2023-08-03 15:24             ` Taylor Blau [this message]
2023-08-04  2:28               ` ZheNing Hu
2023-08-04  8:28                 ` Christian Couder
2023-08-04 18:34                   ` Taylor Blau
2023-08-04 19:00                     ` Junio C Hamano
2023-08-05  8:27                       ` ZheNing Hu
2023-07-27 17:13     ` Konstantin Khomoutov
2023-07-28  3:35       ` ZheNing Hu

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=ZMvGsYSystLu6oBY@nand.local \
    --to=me@ttaylorr.com \
    --cc=adlternative@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).