git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: ZheNing Hu <adlternative@gmail.com>, Git List <git@vger.kernel.org>
Subject: Re: [QUESTION] how to diff one blob with nothing
Date: Thu, 27 Jul 2023 13:46:25 -0400	[thread overview]
Message-ID: <ZMKtcaN7xYaTtkcI@nand.local> (raw)
In-Reply-To: <xmqqila6cz0n.fsf@gitster.g>

On Wed, Jul 26, 2023 at 11:23:52AM -0700, Junio C Hamano wrote:
> ZheNing Hu <adlternative@gmail.com> writes:
>
> >> If you haven't created one, of course it would fail.  It should help
> >> to do
> >>
> >>     $ git hash-object -w --stdin </dev/null
> >>
> >> before running
> >>
> >>     $ git diff 00750edc e69de29bb
> >>
> >
> > This is a viable solution, but it's a bit ugly since a read-only "diff"
> > requires ”write“ an empty blob.
>
> If you do not even have an empty blob, you have no business
> comparing some other blobs you have with it, do you?
>
> If you do not have a file with a single line "hello, world\n" (that
> hashes to 4b5fa63702dd96796042e92787f464e28f09f17d if written in a
> blob), then you cannot do "git diff 4b5fa637" with anything and
> expect it to work.  It is the same thing.
>
> Besides, if you _know_ you want to compare a blob X to emptyness,
> you are better of doing "git cat-file blob X" in the first place.

Yeah, exactly. In 346245a1bb6 (hard-code the empty tree object,
2008-02-13), the rationale was partly that having the empty tree object
is useful for showing some diffs, such as for the initial commit.

But I can't think of a similar argument for the empty blob. Like Junio
said, if you're purposefully diff-ing against the empty blob, wouldn't
you simply want the entire contents anyway? If that's the case, cat-file
seems like a much more appropriate tool.

Thanks,
Taylor

  reply	other threads:[~2023-07-27 17:46 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 [this message]
2023-07-28  3:40         ` ZheNing Hu
2023-08-03  5:16           ` ZheNing Hu
2023-08-03 15:24             ` Taylor Blau
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=ZMKtcaN7xYaTtkcI@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).