git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [QUESTION] how to diff one blob with nothing

From
ZheNing Hu <adlternative@gmail.com>
Date
Aug 3, 2023, 05:16 UTC
Message-ID
<CAOLTT8S=_1Vd2Y4rBqq03JsJ1megRBcx9v-HYAWXe88jDek98Q@mail.gmail.com>
In-Reply-To
<CAOLTT8Ru+3efmUNMOwbhzwRu-FW-SVPYn88-xtrRQiRuweFG+Q@mail.gmail.com>
ZheNing Hu <adlternative@gmail.com> 于2023年7月28日周五 11:40写道:
Show 47 quoted lines
>
> Taylor Blau <me@ttaylorr.com> 于2023年7月28日周五 01:46写道:
> >
> > 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.
> >
>
> 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.

> > Thanks,
> > Taylor
Previous: ZheNing HuNext: Taylor Blau
Message 7 of 15 in “[QUESTION] how to diff one blob with nothing”
  1. ZheNing HuJul 19, 2023
  2. Junio C HamanoJul 19, 2023
  3. ZheNing HuJul 26, 2023
  4. Junio C HamanoJul 26, 2023
  5. Taylor BlauJul 27, 2023
  6. ZheNing HuJul 28, 2023
  7. ZheNing HuAug 3, 2023
  8. Taylor BlauAug 3, 2023
  9. ZheNing HuAug 4, 2023
  10. Christian CouderAug 4, 2023
  11. Taylor BlauAug 4, 2023
  12. Junio C HamanoAug 4, 2023
  13. ZheNing HuAug 5, 2023
  14. Konstantin KhomoutovJul 27, 2023
  15. ZheNing HuJul 28, 2023

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.