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

Re: git ate my home directory :-(

From
Jeff King <peff@peff.net>
Date
Mar 26, 2013, 17:41 UTC
Message-ID
<20130326174059.GA10383@sigill.intra.peff.net>
In-Reply-To
<5151D589.2000002@nod.at>
On Tue, Mar 26, 2013 at 06:06:17PM +0100, Richard Weinberger wrote:
Show 7 quoted lines
> >We could, but that would break the existing behavior for other people
> >(and I assume you mean "when GIT_WORK_TREE is not set at all", as I
> >would think GIT_WORK_TREE=. is explicit enough).
> 
> Is there a valid use case to call git-clean with GIT_DIR set but GIT_WORK_TREE
> not (or to ."")?
> It will delete "." ;)

Yes, setting GIT_DIR but not GIT_WORK_TREE has always been a valid way to work on a repository where you do not want the working tree polluted with your .git file. It's not a common setup, but people do use it. E.g., you might keep ~/mail as a git repo, but do not want the presence of ~/mail/.git to confuse your mail tools. You can keep ~/git/mail.git as just a repository, and do "cd ~/mail && GIT_DIR=~/git/mail.git git foo" (or "git --git-dir=~git/mail.git foo").

Later, we introduced GIT_WORK_TREE (and core.worktree), which provided another way of doing the same thing (instead of the "cd", you could set GIT_WORK_TREE). For the most part, I'd expect setting core.worktree to be the simplest for such setups, as once it is set, you can just do "cd ~/git/mail.git git foo", and everything should just work.

We never deprecated the original "GIT_DIR without GIT_WORK_TREE means '.' is the implicit worktree" behavior, as nobody ever complained, and it would break existing users of the feature.

We could do so now, as long as we provide an escape hatch (and I think spelling that hatch as GIT_WORK_TREE=. is probably sane, but I am open to other suggestions). And in general we try to avoid such breakage without a deprecation period to give people time to fix their scripts and workflows.

> But was kinda shocked that git-clean deletes files outside my git tree.
> I'm aware of -d. But in my case it happened within a fully automated script.
> I simply thought GIT_DIR=.. git-clean -f -d does the right thing...
It did do the right thing; just not the one you expected. :)

The problem is not with "clean", which just happens to be a destructive command, but rather with the notion of what the git tree is when you provide GIT_DIR. Though clean is an obvious problematic command, something like "git reset --hard" could also be destructive. I don't think it makes sense to do any fix that is specific to clean. If there is a fix to be done, it should be about making the working tree lookup algorithm more obvious.

-Peff
Previous: demerphqNext: Junio C Hamano
Message 25 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.