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

Re: git ate my home directory :-(

From
Philip Oakley <philipoakley@iee.org>
Date
Mar 26, 2013, 21:40 UTC
Message-ID
<460E50A0F7A14FA796D6D74E25DA78F3@PhilipOakley>
In-Reply-To
<20130326094844.GA32583@duynguyen-vnpc.dek-tpc.internal>
From: "Duy Nguyen" <pclouds@gmail.com>
Sent: Tuesday, March 26, 2013 9:48 AM
Show 36 quoted lines
> On Tue, Mar 26, 2013 at 08:02:30AM -0000, Philip Oakley wrote:
>> >> Yeah, for historical reasons GIT_WORK_TREE defaults to $(pwd) when
>> >> GIT_DIR is explicitly set.
>> >
>> > And it *WILL* be that way til the end of time.  Unless you are at
>> > the top level of your working tree, you are supposed to tell where
>> > the top level is with GIT_WORK_TREE when you use GIT_DIR.  Always.
>>
>> Should this important warning be part of the git(1) documentation on
>> the
>> environment variables (and possibly other places) given the
>> consequences
>> of this case? It wasn't something I'd appreciated from a simple
>> reading.
>
> Something like this, maybe?
>
> -- 8< --
> Subject: [PATCH] git.txt: document the implicit working tree setting
> with GIT_DIR
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> Documentation/git.txt | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/Documentation/git.txt b/Documentation/git.txt
> index 7efaa59..ce55abf 100644
> --- a/Documentation/git.txt
> +++ b/Documentation/git.txt
> @@ -671,6 +671,8 @@ Git so take care if using Cogito etc.
>  specifies a path to use instead of the default `.git`
>  for the base of the repository.
>  The '--git-dir' command-line option also sets this value.
> + If neither GIT_WORK_TREE nor '--work-tree' is set, the
> + current directory will become the working tree.

I didn't feel this conveyed the Dire Warning effect that would be needed to avoid the original misunderstanding.

It is easy to miss some of the potential consequences when other priorities are pressing.

As Junio wondered, perhaps rhetorically, in a later message "Why do these people set GIT_DIR without setting GIT_WORK_TREE in the first place?"

Perhaps "If the GIT_DIR environment variable is set then it specifies a path to use instead of the default `.git` for the base of the repository. Note that the current directory `.` will be used as the working GIT_WORK_TREE, if not set elsewhere. The --git-dir command-line option also sets the GIT_DIR environment variable."

Show 7 quoted lines
>
> 'GIT_WORK_TREE'::
>  Set the path to the working tree.  The value will not be
> -- 
> 1.8.2.82.gc24b958
> -- 8< --
> --
Philip 
Previous: Duy NguyenNext: Richard Weinberger
Message 18 of 35 in “git ate my home directory :-(”
  1. Richard WeinbergerMar 25, 2013
  2. Jonathan NiederMar 25, 2013
  3. Junio C HamanoMar 25, 2013
  4. Jonathan NiederMar 25, 2013
  5. Junio C HamanoMar 25, 2013
  6. Junio C HamanoMar 25, 2013
  7. Richard WeinbergerMar 25, 2013
  8. Jonathan NiederMar 25, 2013
  9. Junio C HamanoMar 25, 2013
  10. Richard WeinbergerMar 25, 2013
  11. Jonathan NiederMar 25, 2013
  12. Brandon CaseyMar 25, 2013
  13. Philip OakleyMar 26, 2013
  14. Duy NguyenMar 26, 2013
  15. Jeff KingMar 26, 2013
  16. Junio C HamanoMar 26, 2013
  17. Duy NguyenMar 27, 2013
  18. Philip OakleyMar 26, 2013
  19. Richard WeinbergerMar 26, 2013
  20. Jeff KingMar 26, 2013
  21. Richard WeinbergerMar 26, 2013
  22. demerphqMar 26, 2013
  23. Jeff KingMar 26, 2013
  24. demerphqMar 26, 2013
  25. Jeff KingMar 26, 2013
  26. Junio C HamanoMar 26, 2013
  27. Jeff KingMar 26, 2013
  28. 1/3 environment: set GIT_WORK_TREE when we figure out work treeJeff King, Mar 26, 2013
  29. Jonathan NiederMar 26, 2013
  30. 2/3 setup: warn about implicit worktree with $GIT_DIRJeff King, Mar 26, 2013
  31. Jonathan NiederMar 26, 2013
  32. Jeff KingMar 26, 2013
  33. Jonathan NiederMar 26, 2013
  34. Matthieu MoyMar 27, 2013
  35. 3/3 setup: treat GIT_DIR without GIT_WORK_TREE as a bare repoJeff King, Mar 26, 2013

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.