{"thread":{"id":"20824","subject":"diff-files inconsistency with touched files","startedAt":"2009-09-02T17:27:15Z","lastAt":"2009-09-03T16:18:54Z","messageCount":3,"participants":["James Spencer","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"122312","messageId":"4A9EAAF3.3000002@cam.ac.uk","threadId":"20824","inReplyTo":null,"subject":"diff-files inconsistency with touched files","fromName":"James Spencer","fromEmail":"jss43@cam.ac.uk","sentAt":"2009-09-02T17:27:15Z","receivedAt":"2009-09-02T17:27:15Z","isPatch":false,"sender":{"key":"jss43@cam.ac.uk","avatar":null},"body":"Hi,\n\nI am puzzled by the following behaviour:\n\n$ git --version\ngit version 1.6.4.2\n$ git diff-files\n$ touch test\n$ git diff-files\n:100644 100644 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 \n0000000000000000000000000000000000000000 M  test\n$ git diff\n$ git diff-files\n$\n\nI don't understand why git diff-files reports a file is changed when \nthat file is touched nor why running git diff changes this to (what I \nthink is) the correct behaviour.\n\nThanks in advance,\n\n    --James\n"},{"id":"122330","messageId":"20090902192820.GE6900@coredump.intra.peff.net","threadId":"20824","inReplyTo":"4A9EAAF3.3000002@cam.ac.uk","subject":"Re: diff-files inconsistency with touched files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-09-02T19:28:20Z","receivedAt":"2009-09-02T19:28:20Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Sep 02, 2009 at 06:27:15PM +0100, James Spencer wrote:\n\n> $ git diff-files\n> $ touch test\n> $ git diff-files\n> :100644 100644 9daeafb9864cf43055ae93beb0afd6c7d144bfa4\n> 0000000000000000000000000000000000000000 M  test\n> $ git diff\n> $ git diff-files\n> $\n> \n> I don't understand why git diff-files reports a file is changed when\n> that file is touched nor why running git diff changes this to (what I\n> think is) the correct behaviour.\n\nGit uses the stat information of a file to know whether what we have\ncached in the index is up-to-date or not. So in the first diff-files, we\ndon't even have to look at the contents of \"test\"; we see that it hasn't\nchanged since the last time we looked at the contents, and that its\nsha-1 matches what's in the index, so there is no diff.\n\nBy running \"touch\", you have changed the stat information, so we believe\nthere may be a difference. But we don't actually know what's _in_ the\nnew side, so we just print the null sha1 instead of the actual sha1\ncontents.\n\nDiff-files _could_ refresh the cache each time it runs, but we\nintentionally do not do that. Doing so is a little bit expensive, and\nbecause diff-files is intended as a low-level tool for scripts, we give\nthe script the flexibility (and responsibility) of refreshing the cache\nwhen it wants to. So you could do:\n\n  $ git update-index --refresh\n  $ git diff-files\n\nand get clean output.\n\nYou see different behavior from \"git diff\" because it is meant for user\nconsumption and therefore refreshes the cache automatically at the\nbeginning of every run.\n\n-Peff\n"},{"id":"122363","messageId":"4A9FEC6E.9030904@cam.ac.uk","threadId":"20824","inReplyTo":"20090902192820.GE6900@coredump.intra.peff.net","subject":"Re: diff-files inconsistency with touched files","fromName":"James Spencer","fromEmail":"jss43@cam.ac.uk","sentAt":"2009-09-03T16:18:54Z","receivedAt":"2009-09-03T16:18:54Z","isPatch":false,"sender":{"key":"jss43@cam.ac.uk","avatar":null},"body":"Jeff King wrote:\n> On Wed, Sep 02, 2009 at 06:27:15PM +0100, James Spencer wrote:\n> \n>> $ git diff-files\n>> $ touch test\n>> $ git diff-files\n>> :100644 100644 9daeafb9864cf43055ae93beb0afd6c7d144bfa4\n>> 0000000000000000000000000000000000000000 M  test\n>> $ git diff\n>> $ git diff-files\n>> $\n>>\n>> I don't understand why git diff-files reports a file is changed when\n>> that file is touched nor why running git diff changes this to (what I\n>> think is) the correct behaviour.\n> \n> Git uses the stat information of a file to know whether what we have\n> cached in the index is up-to-date or not. So in the first diff-files, we\n> don't even have to look at the contents of \"test\"; we see that it hasn't\n> changed since the last time we looked at the contents, and that its\n> sha-1 matches what's in the index, so there is no diff.\n> \n> By running \"touch\", you have changed the stat information, so we believe\n> there may be a difference. But we don't actually know what's _in_ the\n> new side, so we just print the null sha1 instead of the actual sha1\n> contents.\n> \n> Diff-files _could_ refresh the cache each time it runs, but we\n> intentionally do not do that. Doing so is a little bit expensive, and\n> because diff-files is intended as a low-level tool for scripts, we give\n> the script the flexibility (and responsibility) of refreshing the cache\n> when it wants to. So you could do:\n> \n>   $ git update-index --refresh\n>   $ git diff-files\n> \n> and get clean output.\n> \n> You see different behavior from \"git diff\" because it is meant for user\n> consumption and therefore refreshes the cache automatically at the\n> beginning of every run.\n> \n> -Peff\n\nThanks for your help!\n\n    --James\n"}]}