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

Re: Why does git diff-index show intent-to-add file as "Added"?

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Oct 18, 2020, 16:00 UTC
Message-ID
<55ed2ace-5dfd-55f9-d9a6-da71ff795716@gmail.com>
In-Reply-To
<xmqqimb88v35.fsf@gitster.c.googlers.com>
On 17/10/2020 21:18, Junio C Hamano wrote:
Show 31 quoted lines
> Pratyush Yadav <me@yadavpratyush.com> writes:
> 
>> In this case, running diff-files gives:
>>
>>    :000000 100644 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 A	foo
> 
> Yes, it says "when comparing the index and the working tree, working
> tree side has it, and the index side does not, so it is an addition".
> 
> Of course, if it is truly a new file that the index does not even
> know about, we'd stay silent, but a path that are marked with i-t-a
> bit is what the user told us to keey an eye on, so that is what you
> would get.
> 
>> Running diff-index gives:
>>
>>    :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A	foo
> 
> If this is "diff-index HEAD", then I think it is expected.  "when
> comparing the HEAD and the working tree, working tree side has it,
> and the tree side does not, so it is an addition."  Exactly the same
> story as "diff-files".
> 
> What should happen in "diff-index --cached HEAD", I offhand do not
> know.  "diff-index --cached HEAD" is a request to compare two trees,
> i.e. the tree that _would_ be produced if you wrote the index out as
> a tree (i.e. "git write-tree") right now, and the tree of HEAD.  So
> I think it may be sensible for the command to behave as if the i-t-a
> path does not even exist in the index when it is run with "--cached";
> I may be missing some subtleties that require us to do something
> different, but that is what I would think.

If a user runs `add -N file` then if they run `git reset -p` (which runs `git diff-index --cached HEAD`) it will ask them if they want to remove `file` from the index. If `diff-index --cached` hid i-t-a entries we'd lose that or have to get the i-t-a entries another way. Having said that it does seem strange for `diff-index --cached` to be showing i-t-a entries. Perhaps `diff-index --cached` should default to --ita-invisible-in-index?

Best Wishes
Phillip
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 6 in “Why does git diff-index show intent-to-add file as "Added"?”
  1. Pratyush YadavOct 17, 2020
  2. Junio C HamanoOct 17, 2020
  3. Phillip WoodOct 18, 2020
  4. Junio C HamanoOct 18, 2020
  5. Pratyush YadavOct 27, 2020
  6. Junio C HamanoOct 27, 2020

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.