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

Re: touching a file causes it to be listed using git diff-files

From
Jeff King <peff@peff.net>
Date
Jan 14, 2010, 06:39 UTC
Message-ID
<20100114063939.GA17565@coredump.intra.peff.net>
In-Reply-To
<p06240813c77462aa2cfb@[63.138.152.134]>
On Thu, Jan 14, 2010 at 12:57:05AM -0500, Stephen Bannasch wrote:
Show 10 quoted lines
> >> 'git diff' also stats the files but strangely 'git diff --quiet' doesn't ???
> >
> >I can't reproduce that behavior here on the current "master". Old
> >versions of git used to not do the index refresh for "diff". What
> >version of git are you using?
> 
> The most recent test was on:
> 
> $ git --version
> git version 1.6.6

Ah, OK, I figured it out. It is due to the early return of "--quiet". Since we know we are simply returning a status of "all the same" or "at least one difference", we can quit after finding the first difference.

So if you have two files, "a" and "b", you can try:
  $ touch a
  $ echo changes >b
  $ git diff --quiet
  $ git diff-files

and you will see that 'a' has been updated, because we traverse the files in sorted order and quit only after seeing 'b'.

But if you do instead:
  $ touch b
  $ echo change >a
  $ git diff --quiet
  $ git diff-files
we quit after 'a' and never refresh 'b'.

I don't think it should be considered a bug, though. "git diff" produces the correct result, and it is under no obligation to produce its side effect. If a caller really wants the index refreshed, he should use update-index instead.

-Peff
Previous: Stephen Bannasch
Message 6 of 6 in “touching a file causes it to be listed using git diff-files”
  1. Stephen BannaschJan 13, 2010
  2. Jeff KingJan 14, 2010
  3. Stephen BannaschJan 14, 2010
  4. Jeff KingJan 14, 2010
  5. Stephen BannaschJan 14, 2010
  6. Jeff KingJan 14, 2010

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.