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

behaviour of git diff, GIT_DIR & checked out tree

From
DTDavid Tweed <david.tweed@gmail.com>
Date
Sep 24, 2007, 12:45 UTC
Message-ID
<e1dab3980709240545o32eeefcdkd4bc67abab0e5343@mail.gmail.com>

I'm doing something "sensible people don't do" -- I know this -- but I'm getting results I don't understand, so I'd appreciate any insight.

In a git tracked tree rooted at $HOME/V with git-dir of $HOME/V/.git, if I'm in $HOME/V then

git diff master@{midnight}

tells me the difference between the current modified files in the tree being tracked in V and the specified commit. In a different directory, OUTSIDE of $HOME/V, I tried

env GIT_DIR=$HOME/V/.git git diff master@{midnight}

to get the same effect but, whilst I do get a diff output, it looks like a diff of the commit against an empty tree. (Using

env GIT_DIR=$HOME/V/.git git diff HEAD master@{midnight}
works ok.) I suppose I could alias it to
cd $HOME/V && command && cd -

but that seems a bit clunky; is there another way to explicitly say "working tree for repo with this GIT_DIR" to git diff?

[Why I'm doing this: I actually work on files in the $HOME/V via various other directories containing symlinks to the basic files (with tracked files being pointed to by multiple symlinks). So I'm almost never actually "in" the tracked tree. This usage makes more sense for my tasks than being within the work tree.]

-- 
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
Next: Johannes Schindelin
Message 1 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.