git状态目录是否依赖?

时间:2013-06-20 18:46:03

标签: git

我希望这很简单,我只是奇怪地配置了git,但我不认为这是预期的行为。

我创建了一个简单的git repo

> mkdir tmp
> cd tmp
> touch this
> mkdir that
> touch that/what
> git init
Initialized empty Git repository in /home/.../tmp/.git/
> git add this that
> git commit -a -m "initial commit"
[master (root-commit) 679f2ae] initial commit
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 that/what
 create mode 100644 this

然后我在新创建的git repo中执行状态

> git status
# On branch master
nothing to commit, working directory clean

无需按预期进行任何操作。但是,当我进入目录'that'并执行状态时,我得到以下内容:

> cd that
> git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    that/what
#       deleted:    this
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       what
no changes added to commit (use "git add" and/or "git commit -a")

我的问题是为什么git认为当我的当前工作目录不是回购的根目录时,所有内容都被删除/未跟踪。我认为这不是预期的行为。

2 个答案:

答案 0 :(得分:3)

这不是预期的行为。 我重复了你的命令链,它按预期工作。 我会仔细检查你的'那个'目录中是否有任何奇怪的.git目录或一些奇怪的〜/ .gitconfig配置。

答案 1 :(得分:0)

感谢所有的帮助 - 我想我已经弄明白了。作为我的ps1 var的另一个脚本的一部分,我正在设置一个“GIT_DIR”env var(它用于将当前git分支添加到我的提示,非常有用的imho)。最初我认为我已经检查过git没有使用GIT_DIR - 它至少没有默认设置,但显然它正在以某种身份使用。

我还不清楚git如何/为什么使用这个env var因为我看到的行为不是很直观,我可能会研究一下。我的脚本将GIT_DIR设置为顶级目录,持有... / .git。显然,如果我在不同的目录中,git会使用* GIT_DIR *目录对我的当前目录进行区分。我不明白为什么会有用。

无论如何,将env var更改为MY_GIT_DIR而不是使用GIT_DIR似乎可以解决问题。

得爱env vars ......