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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux