{"thread":{"id":"9995","subject":"behaviour of git diff, GIT_DIR & checked out tree","startedAt":"2007-09-24T12:45:26Z","lastAt":"2007-09-24T18:31:36Z","messageCount":6,"participants":["David Tweed","Johannes Schindelin","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"53913","messageId":"e1dab3980709240545o32eeefcdkd4bc67abab0e5343@mail.gmail.com","threadId":"9995","inReplyTo":null,"subject":"behaviour of git diff, GIT_DIR & checked out tree","fromName":"David Tweed","fromEmail":"david.tweed@gmail.com","sentAt":"2007-09-24T12:45:26Z","receivedAt":"2007-09-24T12:45:26Z","isPatch":false,"sender":{"key":"david.tweed@gmail.com","avatar":null},"body":"I'm doing something \"sensible people don't do\"\n-- I know this -- but I'm getting results I don't\nunderstand, so I'd appreciate any insight.\n\nIn a git tracked tree rooted at $HOME/V with\ngit-dir of $HOME/V/.git, if I'm in $HOME/V then\n\ngit diff master@{midnight}\n\ntells me the difference between the current modified files\nin the tree being tracked in V and the specified commit. In\na different directory, OUTSIDE of $HOME/V, I tried\n\nenv GIT_DIR=$HOME/V/.git git diff master@{midnight}\n\nto get the same effect but, whilst I do get a diff output, it\nlooks like a diff of the commit against an empty tree. (Using\n\nenv GIT_DIR=$HOME/V/.git git diff HEAD master@{midnight}\n\nworks ok.) I suppose I could alias it to\n\ncd $HOME/V && command && cd -\n\nbut that seems a bit clunky; is there another way to explicitly\nsay \"working tree for repo with this GIT_DIR\" to git diff?\n\n[Why I'm doing this: I actually work on files in the $HOME/V\nvia various other directories containing symlinks to the basic\nfiles (with tracked files being pointed to by multiple symlinks).\nSo I'm almost never actually \"in\" the tracked tree. This\nusage makes more sense for my tasks than being within\nthe work tree.]\n\n-- \ncheers, dave tweed__________________________\ndavid.tweed@gmail.com\nRm 124, School of Systems Engineering, University of Reading.\n\"we had no idea that when we added templates we were adding a Turing-\ncomplete compile-time language.\" -- C++ standardisation committee\n"},{"id":"53914","messageId":"Pine.LNX.4.64.0709241400410.28395@racer.site","threadId":"9995","inReplyTo":"e1dab3980709240545o32eeefcdkd4bc67abab0e5343@mail.gmail.com","subject":"Re: behaviour of git diff, GIT_DIR & checked out tree","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-09-24T13:03:11Z","receivedAt":"2007-09-24T13:03:11Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 24 Sep 2007, David Tweed wrote:\n\n> In a git tracked tree rooted at $HOME/V with\n> git-dir of $HOME/V/.git, if I'm in $HOME/V then\n> \n> git diff master@{midnight}\n> \n> tells me the difference between the current modified files\n> in the tree being tracked in V and the specified commit. In\n> a different directory, OUTSIDE of $HOME/V, I tried\n> \n> env GIT_DIR=$HOME/V/.git git diff master@{midnight}\n> \n> to get the same effect but, whilst I do get a diff output, it\n> looks like a diff of the commit against an empty tree.\n\nYes, this is fully expected.\n\nThe @{time} notation accesses the _reflogs_, which are purely local \nbeasts.  They are not transmitted when cloning.\n\nThe rationale: in a distributed environment, you cannot trust others' \ntimestamps.  Therefore we don't.\n\nWe can only (to a certain extent, at least) trust our _own_ timestamp.  \nThat is why we have timestamp access to the reflogs (which are purely \nlocal, as I mentioned above), but we have no way to reference commits by \ntimestamp otherwise.\n\nHth,\nDscho\n"},{"id":"53916","messageId":"e1dab3980709240616p5badae12t23ffd323a0d873d@mail.gmail.com","threadId":"9995","inReplyTo":"Pine.LNX.4.64.0709241400410.28395@racer.site","subject":"Re: behaviour of git diff, GIT_DIR & checked out tree","fromName":"David Tweed","fromEmail":"david.tweed@gmail.com","sentAt":"2007-09-24T13:16:14Z","receivedAt":"2007-09-24T13:16:14Z","isPatch":false,"sender":{"key":"david.tweed@gmail.com","avatar":null},"body":"On 9/24/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> Yes, this is fully expected.\n>\n> The @{time} notation accesses the _reflogs_, which are purely local\n> beasts.  They are not transmitted when cloning.\n\nThanks of your reply; however I suspect this isn't the problem\nhere since I just tried with just master and I get the same thing.\nTo be clear, I'm doing this on the same machine with the same\nuser account as the git directory, just from a directory outside\nthe git tree, eg, the git tracked tree is in $HOME/V and I'm\nin $HOME/A running\n\nenv GIT_DIR=$HOME/V/.git git diff master\n\nAs a guess without looking at the code, what I imagine\nis happening is that git diff limits showing changes to the directory\ntree below $PWD, and when $PWD isn't actually within the git\ndir that ends up somehow as an empty tree.\n\n-- \ncheers, dave tweed__________________________\ndavid.tweed@gmail.com\nRm 124, School of Systems Engineering, University of Reading.\n\"we had no idea that when we added templates we were adding a Turing-\ncomplete compile-time language.\" -- C++ standardisation committee\n"},{"id":"53931","messageId":"7v6420au43.fsf@gitster.siamese.dyndns.org","threadId":"9995","inReplyTo":"Pine.LNX.4.64.0709241400410.28395@racer.site","subject":"Re: behaviour of git diff, GIT_DIR & checked out tree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-24T16:47:08Z","receivedAt":"2007-09-24T16:47:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Mon, 24 Sep 2007, David Tweed wrote:\n>\n>> ... In\n>> a different directory, OUTSIDE of $HOME/V, I tried\n>> \n>> env GIT_DIR=$HOME/V/.git git diff master@{midnight}\n>> \n>> to get the same effect but, whilst I do get a diff output, it\n>> looks like a diff of the commit against an empty tree.\n>\n> Yes, this is fully expected.\n>\n> The @{time} notation accesses the _reflogs_, which are purely local \n> beasts.  They are not transmitted when cloning.\n\nYeah, but my reading of the problem description suggests the two\ncases refer to the same repository (hence the same reflogs).\n\nThe issue is that the second case runs \"git diff <one-tree>\" in\na random directory.  This form is about comparing the part of\nwork tree you are in with a given tree, and does not make _any_\nsense when outside the work tree.  Usually without GIT_DIR\nenvironment, the command would give you an error message.\n\nWith $GIT_DIR, but without $GIT_WORK_TREE, the user is telling\nthe command that it is being run at the top level of the work\ntree and the repository metadata is not in the usual \".git\"\nsubdirectory of the top level of the work tree (in this case, by\ndefinition that is \"$PWD/.git\") but elsewhere where $GIT_DIR\nspecifies.  Because it is very likely that the files under the\nrandom location does not share much resemblance to what are in\n$HOME/V, it is not surprising that the output consisted of many\ndeletions.\n\nIt would be illustrative if David did the following.\n\n\t$ cd $HOME\n        $ cp -a V W\n        $ rm -fr W/.git\n        $ cd W\n        $ GIT_DIR=$HOME/V/.git git diff @{midnight}\n\nNow we are in a random place outside of the work tree\n(i.e. \"W\"), and we drive \"git diff\" with GIT_DIR specified,\ntelling it to pretend that we are at the top level of the work\ntree.  So ~/W/frotz is compared with \"frotz\" at the top level of\nthe commit (which usually is compared with ~/V/frotz), etc.  But\nthe directory we happen to be in very much resembles the work\ntree, so it would give identical results to\n\n\t$ cd $HOME/V\n        $ git diff @{midnight}\n"},{"id":"53934","messageId":"e1dab3980709241009q71f9a40r1f8b551b417f7475@mail.gmail.com","threadId":"9995","inReplyTo":"7v6420au43.fsf@gitster.siamese.dyndns.org","subject":"Re: behaviour of git diff, GIT_DIR & checked out tree","fromName":"David Tweed","fromEmail":"david.tweed@gmail.com","sentAt":"2007-09-24T17:09:20Z","receivedAt":"2007-09-24T17:09:20Z","isPatch":false,"sender":{"key":"david.tweed@gmail.com","avatar":null},"body":"On 9/24/07, Junio C Hamano <gitster@pobox.com> wrote:\n> It would be illustrative if David did the following.\n>\n>         $ cd $HOME\n>         $ cp -a V W\n>         $ rm -fr W/.git\n>         $ cd W\n>         $ GIT_DIR=$HOME/V/.git git diff @{midnight}\n>\n> Now we are in a random place outside of the work tree\n> (i.e. \"W\"), and we drive \"git diff\" with GIT_DIR specified,\n> telling it to pretend that we are at the top level of the work\n> tree.  So ~/W/frotz is compared with \"frotz\" at the top level of\n> the commit (which usually is compared with ~/V/frotz), etc.  But\n> the directory we happen to be in very much resembles the work\n> tree, so it would give identical results to\n>\n>         $ cd $HOME/V\n>         $ git diff @{midnight}\n\nTo separate the two issues, I did all the commands to the diff\nabove and then removed one directory from the tree in W.\n\nGIT_DIR=$HOME/V/.git git diff master~1\n(which ought not need reflogs, right) and it gave a diff between\nthe contents of W and master~1. I also tried with commit\nmaster@{midnight} and that also gave the difference between\nW and the last commit yesterday. So Junio's explanation of what's going on\nis right. I'm just asking if there's a way to say\n\"the `working dir' associated with this git dir\" explicitly (in the same\nway I can use `HEAD' to refer to the topmost commit on the\ncurrent branch) when you're not somewhere within the 'working dir'.\nIf there's not I can alias around it with\n\"cd $HOME/V && command && cd -\". (As I say, for reasons unrelated\nto git usage I don't actually \"do work\" within the tracked tree.)\n\nMany thanks,\n\n-- \ncheers, dave tweed__________________________\ndavid.tweed@gmail.com\nRm 124, School of Systems Engineering, University of Reading.\n\"we had no idea that when we added templates we were adding a Turing-\ncomplete compile-time language.\" -- C++ standardisation committee\n"},{"id":"53938","messageId":"7vwsufap9z.fsf@gitster.siamese.dyndns.org","threadId":"9995","inReplyTo":"e1dab3980709241009q71f9a40r1f8b551b417f7475@mail.gmail.com","subject":"Re: behaviour of git diff, GIT_DIR & checked out tree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-24T18:31:36Z","receivedAt":"2007-09-24T18:31:36Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"David Tweed\" <david.tweed@gmail.com> writes:\n\n> ... I'm just asking if there's a way to say\n> \"the `working dir' associated with this git dir\" explicitly (in the same\n> way I can use `HEAD' to refer to the topmost commit on the\n> current branch) when you're not somewhere within the 'working dir'.\n\nNot for \"git diff <one-tree>\" which is a way to diff the _part_\nof work tree you are _currently in_ with the given tree, nor for\n\"git diff\" which is to do the same with the index.  With these\ncommands (and others that error out when you run without GIT_DIR\noutside the work tree), you are really expected to be _in_ the\nsubdirectory you are interested in.\n\nGIT_WORK_TREE is somewhat related but is a different issue, by\nthe way.  It is to let you say where the top level of the work\ntree is.  It does not change the fact that the way for you to\nexpress which subdirectory in the work tree you are interested\nin to work tree commands is by your $PWD relative to the top of\nthe work tree.\n"}]}