git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* strange behavior of git diff-index
@ 2019-05-22 10:00 Oussama Ghorbel
  2019-05-22 14:54 ` Johannes Schindelin
  0 siblings, 1 reply; 3+ messages in thread
From: Oussama Ghorbel @ 2019-05-22 10:00 UTC (permalink / raw)
  To: git

Hi,

git diff-index is giving me incorrect information, however if I run git diff, then git diff-index again it will show the correct information.
The steps are the following:
$ git diff-index --name-only HEAD
git appears to list all files in the project irrespective if they modified or not
$ git diff
$ git diff --cached
will show nothing. So I don't have any modification. 
Now strangely if I run git diff-index, it will also show nothing which is correction behavior.

my git version is 2.7.4
Any explanation?

Thanks,
Oussama

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: strange behavior of git diff-index
  2019-05-22 10:00 strange behavior of git diff-index Oussama Ghorbel
@ 2019-05-22 14:54 ` Johannes Schindelin
  2019-05-22 15:27   ` Oussama Ghorbel
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2019-05-22 14:54 UTC (permalink / raw)
  To: Oussama Ghorbel; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1343 bytes --]

Hi Oussama,

On Wed, 22 May 2019, Oussama Ghorbel wrote:

> git diff-index is giving me incorrect information, however if I run git diff, then git diff-index again it will show the correct information.
> The steps are the following:
> $ git diff-index --name-only HEAD
> git appears to list all files in the project irrespective if they modified or not
> $ git diff
> $ git diff --cached
> will show nothing. So I don't have any modification. 
> Now strangely if I run git diff-index, it will also show nothing which is correction behavior.
>
> my git version is 2.7.4
> Any explanation?

The low-level `diff-index` command is meant to be used in scripts, and
does specifically *not* refresh the index before running. Meaning that it
could possibly mistake a file for being modified even if it is not
modified, just because it is marked "modified" in the index [*1*].

Short answer: use the high-level command `git diff` that is intended for
human consumption.

Ciao,
Johannes

Footnote *1*: It is actually a bit more complicated than that: the index
stores metadata such as mtime, size, uid, etc, and compares that to the
metadata on disk. If there is any mismatch, or if everything matches but
the mtime *also* matches the index file's itself, the file is considered
not up to date, i.e. marked as modified.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: strange behavior of git diff-index
  2019-05-22 14:54 ` Johannes Schindelin
@ 2019-05-22 15:27   ` Oussama Ghorbel
  0 siblings, 0 replies; 3+ messages in thread
From: Oussama Ghorbel @ 2019-05-22 15:27 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

Hi Johannes,

Thanks a lot for the clarification!

Regards,
Oussama
On 5/22/19 4:54 PM, Johannes Schindelin wrote:
> Hi Oussama,
>
> On Wed, 22 May 2019, Oussama Ghorbel wrote:
>
>> git diff-index is giving me incorrect information, however if I run git diff, then git diff-index again it will show the correct information.
>> The steps are the following:
>> $ git diff-index --name-only HEAD
>> git appears to list all files in the project irrespective if they modified or not
>> $ git diff
>> $ git diff --cached
>> will show nothing. So I don't have any modification.
>> Now strangely if I run git diff-index, it will also show nothing which is correction behavior.
>>
>> my git version is 2.7.4
>> Any explanation?
> The low-level `diff-index` command is meant to be used in scripts, and
> does specifically *not* refresh the index before running. Meaning that it
> could possibly mistake a file for being modified even if it is not
> modified, just because it is marked "modified" in the index [*1*].
>
> Short answer: use the high-level command `git diff` that is intended for
> human consumption.
>
> Ciao,
> Johannes
>
> Footnote *1*: It is actually a bit more complicated than that: the index
> stores metadata such as mtime, size, uid, etc, and compares that to the
> metadata on disk. If there is any mismatch, or if everything matches but
> the mtime *also* matches the index file's itself, the file is considered
> not up to date, i.e. marked as modified.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-05-22 15:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 10:00 strange behavior of git diff-index Oussama Ghorbel
2019-05-22 14:54 ` Johannes Schindelin
2019-05-22 15:27   ` Oussama Ghorbel

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).