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

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git