threads / discuss / 52929

GIT_WORK_TREE; a recipe for disaster

Subject: GIT_WORK_TREE; a recipe for disaster

## tl;dr

2 messages between Mar 3, 2020 and Mar 3, 2020.

replies: 1people: 2as markdown or json

Phillip Susi· Mar 3, 2020, 13:53 UTC · lore

I'm using git for windows version 2.25.0.windows.1. Yesterday I was in a bash command line and changed directories to another project. I ran git status and it complained about basically everything being deleted when the files were sitting there just fine. I thought that maybe it is confused since I upgraded git recently and so I ran git checkout -f and git clean -xfd to make sure that the working directory would be restored to a pristine state. I later changed back to the first project directory where I was horrified to see that all of the files from the second project had been checked out, and the changes in that project that I had been working on for a few days had been deleted.

It seems the cause of this is that I had opened git bash from the git gui menu instead of from the windows explorer menu. In previous releases, this cause GIT_DIR to be set ( I believe ), and so that session of git bash was tied to that repoistory even if you changed directories to another repository. I always thought this was rather annoying, but things seem to be worse now that I have upgraded, because git now uses the index and hisotry log etc from the cwd, but compares that index to files elsewhere. This seems like a recipe for disaster. Why does git gui set these environment variables at all, and could it please stop?

Philip Oakley· Mar 3, 2020, 14:22 UTC · re: Phillip Susi · lore

Re: GIT_WORK_TREE; a recipe for disaster

On 03/03/2020 13:53, Phillip Susi wrote:
Show 22 quoted lines
> I'm using git for windows version 2.25.0.windows.1.  Yesterday I was in
> a bash command line and changed directories to another project.  I ran
> git status and it complained about basically everything being deleted
> when the files were sitting there just fine.  I thought that maybe it is
> confused since I upgraded git recently and so I ran git checkout -f and
> git clean -xfd to make sure that the working directory would be restored
> to a pristine state.  I later changed back to the first project
> directory where I was horrified to see that all of the files from the
> second project had been checked out, and the changes in that project
> that I had been working on for a few days had been deleted.
>
> It seems the cause of this is that I had opened git bash from the git
> gui menu instead of from the windows explorer menu.  In previous
> releases, this cause GIT_DIR to be set ( I believe ), and so that
> session of git bash was tied to that repoistory even if you changed
> directories to another repository.  I always thought this was rather
> annoying, but things seem to be worse now that I have upgraded, because
> git now uses the index and hisotry log etc from the cwd, but compares
> that index to files elsewhere.  This seems like a recipe for disaster.
> Why does git gui set these environment variables at all, and could it
> please stop?
>

Probably worth including Pratyush Yadav for the git-gui maintenance aspect. -- Philip

← back to recent threads