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 4, 2023, 02:28 UTC
Message-ID
<CAOLTT8Tc9NevyUfwiPscEH7BqShSscb=iZP4r+7mjsEwouLeXg@mail.gmail.com>
In-Reply-To
<ZMvGsYSystLu6oBY@nand.local>
Taylor Blau <me@ttaylorr.com> 于2023年8月3日周四 23:24写道:
Show 35 quoted lines
>
> 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.)
>

Actually, there is no need to support a default empty blob. For example, with the command "git diff --no-index <file> /dev/null", it can compare a file with /dev/null, but it can only compare <file> and not <oid>. Therefore, using commands like "git diff <oid> /dev/null", "git diff --no-index <oid> /dev/null", or even "git diff <oid> --stdin" could potentially solve this issue.

Thanks, ZheNing Hu

Previous: Taylor BlauNext: Christian Couder
Message 9 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.