# Bug(feature?) on git-diff-files

4 messages from 2019-04-11 to 2019-04-12. Participants: NoName Req, Jeff King, Duy Nguyen.
Thread: https://gitlist.dev/t/50918

## NoName Req, 2019-04-11 12:47

Subject: Bug(feature?) on git-diff-files
Message-ID: <CABgj7us=Rk3EUvd2EVVqsYKDUGS7VfAX09SpW04fB26cgntw5g@mail.gmail.com>
URL: https://gitlist.dev/e/CABgj7us%3DRk3EUvd2EVVqsYKDUGS7VfAX09SpW04fB26cgntw5g%40mail.gmail.com

```
Summary
   `git -C (folder path) diff-files --name-only` output is not correct

Steps to Reproduce
1. Apply change to a clean git repository. Go to another folder (not
within this repository) and apply the command
   `git -C repo-path diff-files --name-only`
The above command lists dirty files in that repository.
2. Now undo your changes on the repository
3. Issue the same command. It still lists the file.

More Information

`git -C repo-path diff`  command doesn't seem to have this problem.

System Information

Arch Linux 5.0.7-arch1-1-ARCH
git version 2.21.0

```

## Jeff King, 2019-04-11 12:57

Subject: Re: Bug(feature?) on git-diff-files
Message-ID: <20190411125703.GA26995@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20190411125703.GA26995%40sigill.intra.peff.net
In-Reply-To: <CABgj7us=Rk3EUvd2EVVqsYKDUGS7VfAX09SpW04fB26cgntw5g@mail.gmail.com>

```
On Thu, Apr 11, 2019 at 03:47:58PM +0300, NoName Req wrote:

> Summary
>    `git -C (folder path) diff-files --name-only` output is not correct
> 
> Steps to Reproduce
> 1. Apply change to a clean git repository. Go to another folder (not
> within this repository) and apply the command
>    `git -C repo-path diff-files --name-only`
> The above command lists dirty files in that repository.
> 2. Now undo your changes on the repository
> 3. Issue the same command. It still lists the file.
> 
> More Information
> 
> `git -C repo-path diff`  command doesn't seem to have this problem.

Try running `git update-index --refresh` before running `diff-files`.

Unlike git-diff, git-diff-files is plumbing that is meant to be called
from scripts. So it is up to the script writer to decide when the index
should be refreshed from the actual filesystem (which makes sense, e.g.,
if you're going to do it once at the start of the script and then make a
bunch of separate diff-related calls).

Until that happens, diff-files will see only that the entry is
stat-dirty, and report it as a potential change.

-Peff

```

## Duy Nguyen, 2019-04-11 12:56

Subject: Re: Bug(feature?) on git-diff-files
Message-ID: <CACsJy8B0dmonaCuAmT6wNJae8iX0JxUOvU-P=zvjVUrQnoHoUw@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8B0dmonaCuAmT6wNJae8iX0JxUOvU-P%3DzvjVUrQnoHoUw%40mail.gmail.com
In-Reply-To: <CABgj7us=Rk3EUvd2EVVqsYKDUGS7VfAX09SpW04fB26cgntw5g@mail.gmail.com>

```
On Thu, Apr 11, 2019 at 7:49 PM NoName Req <nonamereq29@gmail.com> wrote:
>
> Summary
>    `git -C (folder path) diff-files --name-only` output is not correct
>
> Steps to Reproduce
> 1. Apply change to a clean git repository. Go to another folder (not
> within this repository) and apply the command
>    `git -C repo-path diff-files --name-only`
> The above command lists dirty files in that repository.
> 2. Now undo your changes on the repository
> 3. Issue the same command. It still lists the file.
>
> More Information
>
> `git -C repo-path diff`  command doesn't seem to have this problem.

I haven't tried to reproduce. But my first impression is diff-files,
as a low-level plumbing sometimes requires you to refresh the index
first. Sometimes without that, you'll get wrong output.

"git diff" is a more high-level command that always refreshes the
index internally.

>
> System Information
>
> Arch Linux 5.0.7-arch1-1-ARCH
> git version 2.21.0



-- 
Duy

```

## NoName Req, 2019-04-12 12:41

Subject: Re: Bug(feature?) on git-diff-files
Message-ID: <CABgj7uu95Pg7jJY1CN7kUS-SWE6+FCgQshuzWWRrhMqBd_zMMA@mail.gmail.com>
URL: https://gitlist.dev/e/CABgj7uu95Pg7jJY1CN7kUS-SWE6%2BFCgQshuzWWRrhMqBd_zMMA%40mail.gmail.com
In-Reply-To: <CACsJy8B0dmonaCuAmT6wNJae8iX0JxUOvU-P=zvjVUrQnoHoUw@mail.gmail.com>

```
Okay thanks for the reply. I didn't know about git update-index will
try that now.

On Thu, Apr 11, 2019 at 3:57 PM Duy Nguyen <pclouds@gmail.com> wrote:
>
> On Thu, Apr 11, 2019 at 7:49 PM NoName Req <nonamereq29@gmail.com> wrote:
> >
> > Summary
> >    `git -C (folder path) diff-files --name-only` output is not correct
> >
> > Steps to Reproduce
> > 1. Apply change to a clean git repository. Go to another folder (not
> > within this repository) and apply the command
> >    `git -C repo-path diff-files --name-only`
> > The above command lists dirty files in that repository.
> > 2. Now undo your changes on the repository
> > 3. Issue the same command. It still lists the file.
> >
> > More Information
> >
> > `git -C repo-path diff`  command doesn't seem to have this problem.
>
> I haven't tried to reproduce. But my first impression is diff-files,
> as a low-level plumbing sometimes requires you to refresh the index
> first. Sometimes without that, you'll get wrong output.
>
> "git diff" is a more high-level command that always refreshes the
> index internally.
>
> >
> > System Information
> >
> > Arch Linux 5.0.7-arch1-1-ARCH
> > git version 2.21.0
>
>
>
> --
> Duy

```
