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

Re: behaviour of git diff, GIT_DIR & checked out tree

From
DTDavid Tweed <david.tweed@gmail.com>
Date
Sep 24, 2007, 17:09 UTC
Message-ID
<e1dab3980709241009q71f9a40r1f8b551b417f7475@mail.gmail.com>
In-Reply-To
<7v6420au43.fsf@gitster.siamese.dyndns.org>
On 9/24/07, Junio C Hamano <gitster@pobox.com> wrote:
Show 18 quoted lines
> It would be illustrative if David did the following.
>
>         $ cd $HOME
>         $ cp -a V W
>         $ rm -fr W/.git
>         $ cd W
>         $ GIT_DIR=$HOME/V/.git git diff @{midnight}
>
> Now we are in a random place outside of the work tree
> (i.e. "W"), and we drive "git diff" with GIT_DIR specified,
> telling it to pretend that we are at the top level of the work
> tree.  So ~/W/frotz is compared with "frotz" at the top level of
> the commit (which usually is compared with ~/V/frotz), etc.  But
> the directory we happen to be in very much resembles the work
> tree, so it would give identical results to
>
>         $ cd $HOME/V
>         $ git diff @{midnight}

To separate the two issues, I did all the commands to the diff above and then removed one directory from the tree in W.

GIT_DIR=$HOME/V/.git git diff master~1 (which ought not need reflogs, right) and it gave a diff between the contents of W and master~1. I also tried with commit master@{midnight} and that also gave the difference between W and the last commit yesterday. So Junio's explanation of what's going on is right. I'm just asking if there's a way to say "the `working dir' associated with this git dir" explicitly (in the same way I can use `HEAD' to refer to the topmost commit on the current branch) when you're not somewhere within the 'working dir'. If there's not I can alias around it with "cd $HOME/V && command && cd -". (As I say, for reasons unrelated to git usage I don't actually "do work" within the tracked tree.)

Many thanks,
-- 
cheers, dave tweed__________________________
david.tweed@gmail.com
Rm 124, School of Systems Engineering, University of Reading.
"we had no idea that when we added templates we were adding a Turing-
complete compile-time language." -- C++ standardisation committee
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “behaviour of git diff, GIT_DIR & checked out tree”
  1. David TweedSep 24, 2007
  2. Johannes SchindelinSep 24, 2007
  3. David TweedSep 24, 2007
  4. Junio C HamanoSep 24, 2007
  5. David TweedSep 24, 2007
  6. Junio C HamanoSep 24, 2007

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.