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

Re: Git diff-file bug?

From
Jeff King <peff@peff.net>
Date
Sep 28, 2012, 20:23 UTC
Message-ID
<20120928202330.GA5770@sigill.intra.peff.net>
In-Reply-To
<CAEkqydxRy3ukSWyQ53Tiosq+DMWWLG=AVuZk+Jm79Y5SaRmeDw@mail.gmail.com>
On Fri, Sep 28, 2012 at 07:55:10PM +0100, Scott Batchelor wrote:
> I'm fairly new to git and am witnessing some strange behavior with git
> that I suspect may be a bug. Can anyone set my mind at rest.
It's not a bug.
> Every so often (I've not quite figured out the exact set of
> circumstances yet)  "git diff-files" shows that every file in my repo
> is modified, when I expect none to be.

Diff-files only looks at the cached sha1 in the index. It will not re-read the file to update its index entry if its stat information appears out of date. So what is happening is that another program[1] is updating the timestamp or other information about each file, but not the content. Diff-files does not re-read the content to find out there is in fact no change.

If you are using plumbing like diff-files, you are expected to run "git update-index --refresh" yourself first. The reasoning is that for performance reasons, a script that issues many git commands would only want to pay the price to refresh the index once, at the beginning of the script.

If you use the "git diff" porcelain, it will automatically refresh the index for you.

> If I type "git status" (which shows what I expect - no files modified)
> and then "git diff-files" again, git now shows that no files have been
> modified (which is what I expect). It's like "git status" is resetting
> something that "git diff-files" uses.

Exactly. "git status" automatically refreshes the index, and the result is saved.

> I'm trying to figure out what the problem with "git diff-files" is
> because gitk uses it under the hood, and I think that gitk is
> reporting  erroneous changes (which are also reset by performing a
> "git status" in the repo) in the "patch" files list.

gitk should probably be calling "update-index --refresh" on startup. If it already is, then it may be that whatever is updating the files is doing it while gitk is running.

-Peff
[1] Usually stat updates are caused by another program. But we have had
    cases where unusual filesystems yielded inconsistent results from
    stat().
Previous: Scott BatchelorNext: Jeff King
Message 2 of 18 in “Git diff-file bug?”
  1. Scott BatchelorSep 28, 2012
  2. Jeff KingSep 28, 2012
  3. gitk: refresh the index before running diff-filesJeff King, Sep 28, 2012
  4. Junio C HamanoSep 28, 2012
  5. Andreas SchwabSep 28, 2012
  6. Jeff KingSep 28, 2012
  7. Junio C HamanoSep 28, 2012
  8. Jeff KingSep 28, 2012
  9. Junio C HamanoSep 28, 2012
  10. Andreas SchwabSep 28, 2012
  11. Paul MackerrasSep 30, 2012
  12. Jeff KingSep 30, 2012
  13. Jonathan NiederSep 30, 2012
  14. Jeff KingOct 1, 2012
  15. Junio C HamanoOct 1, 2012
  16. Junio C HamanoSep 28, 2012
  17. Scott BatchelorOct 3, 2012
  18. Drew NorthupOct 3, 2012

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.