用git --git-dir和--work-tree混淆结果

时间:2018-03-26 07:59:30

标签: git

运行以下内容:

git init --bare bare
git init not-bare
pushd not-bare
echo something > file
git add file
git commit -m something
git remote add bare ../bare
git push bare master
rm -rf .git
popd
git --work-tree=not-bare --git-dir=bare status

给我以下输出:

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    file

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    file

这让我感到困惑。考虑到工作树(not-bare)的内容与&#34;预期的&#34;完全匹配,我本来期望的。该提交的内容,该命令将返回空,表示状态不变。

任何人都可以解释为什么我会得到我的结果吗?

1 个答案:

答案 0 :(得分:0)

在考虑了@evolutionxbox在评论中所说的内容后,我回到了手册页,并从man git-status找到了以下内容:

Displays paths that have differences between the index file and the current HEAD
commit, paths that have differences between the working tree and the index file,
and paths in the working tree that are not tracked by Git (and are not ignored by
gitignore(5)).

因此,查看bare和已删除的not-bare/.git中的文件,我会在裸页面中找到一个文件,index,如手册页中所述

现在这一切都有意义,因为ls-files在两个git目录之间有所不同:

git --git-dir=bare ls-files
# no output
git --git-dir=not-bare/.git ls-files
file

总而言之,git status无法理解我要求它做什么,因为指定的git-dir是一个简单的回购,除此之外拥有工作树,也没有相应的索引。