# "git diff-files" command reports differences that don't exist

5 messages from 2021-03-05 to 2021-03-05. Participants: Michael Brown, Junio C Hamano, Eric Sunshine.
Thread: https://gitlist.dev/t/55264

## Michael Brown, 2021-03-05 19:28

Subject: "git diff-files" command reports differences that don't exist
Message-ID: <4210f5f1-dd7e-f425-6ab2-e220a33e82bf@discourse.org>
URL: https://gitlist.dev/e/4210f5f1-dd7e-f425-6ab2-e220a33e82bf%40discourse.org

```
What did you do before the bug happened? (Steps to reproduce your issue)

1. Be in any existing repository in a clean state (I tested with 2 existing
   repositories and 1 completely fresh)
1. run `git diff-files`, see no output
1. touch an existing file: `touch a`
1. run `git diff-files`

What did you expect to happen? (Expected behavior)

`git diff-files` should show no output

What happened instead? (Actual behavior)

`git diff-files` reported a difference on the touched file.

What's different between what you expected and what actually happened?

git reports a difference where none exists

Anything else you want to add:

This difference vanished after running other commands (e.g. `git diff`).

A complete reproduction using docker is below:

$ docker run -it --rm debian:latest
root@d24ec0793bdf:/# apt update && apt -y install git
…
root@d24ec0793bdf:/# mkdir ~/new-repo
root@d24ec0793bdf:/# cd ~/new-repo
root@d24ec0793bdf:~/new-repo# git init
Initialized empty Git repository in /root/new-repo/.git/
root@d24ec0793bdf:~/new-repo# touch a
root@d24ec0793bdf:~/new-repo# git add a
root@d24ec0793bdf:~/new-repo# git config --global user.email
'user@example.net'
root@d24ec0793bdf:~/new-repo# git config --global user.name 'Example User'
root@d24ec0793bdf:~/new-repo# git commit -m 'initial'
[master (root-commit) 791011f] initial
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
root@d24ec0793bdf:~/new-repo# git diff-files
root@d24ec0793bdf:~/new-repo# touch a
root@d24ec0793bdf:~/new-repo# git diff-files
:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
0000000000000000000000000000000000000000 M    a
root@d24ec0793bdf:~/new-repo# git diff
root@d24ec0793bdf:~/new-repo# git diff-files
root@d24ec0793bdf:~/new-repo# git --version
git version 2.20.1


[System Info]
git version:
git version 2.30.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.11.1-arch1-1 #1 SMP PREEMPT Tue, 23 Feb 2021 14:05:30
+0000 x86_64
compiler info: gnuc: 10.2
libc info: glibc: 2.33
$SHELL (typically, interactive shell): /bin/bash

This same behaviour was also found in:

* 2.20.1
* 2.25.1

[Enabled Hooks]
(none)

-- 
Michael Brown
Civilized Discourse Construction Kit, Inc.
https://www.discourse.org/


```

## Junio C Hamano, 2021-03-05 21:49

Subject: Re: "git diff-files" command reports differences that don't exist
Message-ID: <xmqqa6rh9sph.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqqa6rh9sph.fsf%40gitster.c.googlers.com
In-Reply-To: <4210f5f1-dd7e-f425-6ab2-e220a33e82bf@discourse.org>

```
Michael Brown <michael.brown@discourse.org> writes:

> What did you do before the bug happened? (Steps to reproduce your issue)
>
> 1. Be in any existing repository in a clean state (I tested with 2 existing
>    repositories and 1 completely fresh)
> 1. run `git diff-files`, see no output
> 1. touch an existing file: `touch a`
> 1. run `git diff-files`

This is totally expected behaviour.  In general when you are working
with plumbing commands like diff-files and diff-index, you are
expected to do "update-index --refresh" upfront.

A plumbing command "git diff" has an equivalent of "update-index
--refresh" built into it, but the plumbing commands are designed
to be used in scripts, and in order to allow scripting programmers
to avoid making unnecessary "update-index --refresh", e.g.

	git update-index --refresh
	git diff-files | use diff-files output
	git diff-index | use diff-index output

they leave it the responsibility of the calling script (or the end
user who directly use them from the command line) to refresh the
cached stat information as necessary.




```

## Eric Sunshine, 2021-03-05 22:18

Subject: Re: "git diff-files" command reports differences that don't exist
Message-ID: <CAPig+cSRKJUhwMagx_h21pJbBiX9paA5cvDbudDNcRVea6g3Mg@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcSRKJUhwMagx_h21pJbBiX9paA5cvDbudDNcRVea6g3Mg%40mail.gmail.com
In-Reply-To: <xmqqa6rh9sph.fsf@gitster.c.googlers.com>

```
On Fri, Mar 5, 2021 at 4:50 PM Junio C Hamano <gitster@pobox.com> wrote:
> This is totally expected behaviour.  In general when you are working
> with plumbing commands like diff-files and diff-index, you are
> expected to do "update-index --refresh" upfront.
>
> A plumbing command "git diff" has an equivalent of "update-index
> --refresh" built into it, but the plumbing commands are designed
> to be used in scripts, and in order to allow scripting programmers
> to avoid making unnecessary "update-index --refresh", e.g.

Did you mean:

    A porcelain command "git diff" has an equivalent...

?

```

## Michael Brown, 2021-03-05 22:20

Subject: Re: "git diff-files" command reports differences that don't exist
Message-ID: <b3774f98-d2aa-3ae2-2aa5-c80339684c50@discourse.org>
URL: https://gitlist.dev/e/b3774f98-d2aa-3ae2-2aa5-c80339684c50%40discourse.org
In-Reply-To: <xmqqa6rh9sph.fsf@gitster.c.googlers.com>

```
On 2021-03-05 4:49 p.m., Junio C Hamano wrote:
> This is totally expected behaviour.  In general when you are working
> with plumbing commands like diff-files and diff-index, you are
> expected to do "update-index --refresh" upfront.
Thanks. I wondered if since it was a plumbing command there might have
been something I was missing but didn't know where to look.

Cheers.

-- 
Michael Brown
Civilized Discourse Construction Kit, Inc.
https://www.discourse.org/

```

## Junio C Hamano, 2021-03-05 22:28

Subject: Re: "git diff-files" command reports differences that don't exist
Message-ID: <xmqq1rct9qwh.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqq1rct9qwh.fsf%40gitster.c.googlers.com
In-Reply-To: <CAPig+cSRKJUhwMagx_h21pJbBiX9paA5cvDbudDNcRVea6g3Mg@mail.gmail.com>

```
Eric Sunshine <sunshine@sunshineco.com> writes:

> On Fri, Mar 5, 2021 at 4:50 PM Junio C Hamano <gitster@pobox.com> wrote:
>> This is totally expected behaviour.  In general when you are working
>> with plumbing commands like diff-files and diff-index, you are
>> expected to do "update-index --refresh" upfront.
>>
>> A plumbing command "git diff" has an equivalent of "update-index
>> --refresh" built into it, but the plumbing commands are designed
>> to be used in scripts, and in order to allow scripting programmers
>> to avoid making unnecessary "update-index --refresh", e.g.
>
> Did you mean:
>
>     A porcelain command "git diff" has an equivalent...

Yes.

```
