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

Re: git diff-index --raw HEAD and git diff --raw HEAD output the same thing?

From
Ping Yin <pkufranky@gmail.com>
Date
Mar 2, 2008, 06:07 UTC
Message-ID
<46dff0320803012207g450f7447h7266a059194709f0@mail.gmail.com>
In-Reply-To
<7vbq5xvfpk.fsf@gitster.siamese.dyndns.org>
On Sun, Mar 2, 2008 at 1:48 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
>
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>  > On Sat, 1 Mar 2008, Ping Yin wrote:
>  >
>  >> Strange things is this line
>  >> :160000 160000 34f279b1662a6bef6a8fdea1827bbdbd80f12444
>  >> 0000000000000000000000000000000000000000 M      commonmake
>  >>
>  >> why mod is 160000 while sha1 is 0000...
>  >
>  > This indicates that a submodule (160000) was deleted (00000).  It is
>  > easier not to handle a deletion as mode change...
>
>  Read the question again.
>
>  When you compare something with a work tree state, and when the work tree
>  state is dirty, we always show 0{40} to mean "it is dirty and we do not
>  know what the object name of that thing is, until you actuallly run
>  git-update-index (or git-add) it" (and at that point it would stop being
>  dirty).  For blobs (be it a regular file or a symbolic link), this has an
>  advantage of not having to run hash-object to obtain the object name of an
>  object that would be created if you actually did git-add it.
>
>  When we check if it is dirty, we already do an lstat(2) and know the type
>  of it, so we can show the mode bits.  So you will see 100644, 100755 or
>  120000 for blobs.  Similarly for a submodule.
>
>  For a submodule, we could read the value from $sub/.git/HEAD, but it is
>  more consistent to show 0{40} on the work tree side (typically the right
>  hand side, unless you use -R).
>

I should read the git-diff/git-diff-index man pages more carefully. It says "<sha1> is shown as all 0's if a file is new on the filesystem and it is out of sync with the index"

But unlike git-diff-index, git-diff does the right thing for me

$ git diff --raw HEAD :160000 160000 34f279b1662a6bef6a8fdea1827bbdbd80f12444 c1f46b3f10cc041e196c388490ddb049dacc7dc0 M commonmake

while git diff-index desn't

$ git diff-index --raw HEAD :160000 160000 34f279b1662a6bef6a8fdea1827bbdbd80f12444 0000000000000000000000000000000000000000 M commonmake

Maybe the man page should clarify the different behaviour of git-diff.

I really want the real sha1 instead of 0{40} in my submodule summary patch, or i have to use git-diff instead of git-diff-index

-- 
Ping Yin
Previous: Junio C HamanoNext: Ping Yin
Message 4 of 6 in “git diff-index --raw HEAD and git diff --raw HEAD output the same thing?”
  1. Ping YinMar 1, 2008
  2. Johannes SchindelinMar 1, 2008
  3. Junio C HamanoMar 2, 2008
  4. Ping YinMar 2, 2008
  5. Ping YinMar 2, 2008
  6. Fwd: git diff-index --raw HEAD and git diff --raw HEAD output the same thing?Ping Yin, Mar 2, 2008

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.