与git-git-dir和-work-tree相关的结果



运行以下操作:

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(与该提交中的"预期"内容完全匹配,命令将返回空,表明状态不变。

谁能解释为什么我会得到我做的结果?

在考虑@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中的文件,我发现了一个Bare Repo中缺少index的文件,如MAN PAGE中所述。

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

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

因此,总而言之,git status无法理解我要它的工作,因为指定的git-dir是一个裸露的回购,除了没有工作树外,它还没有相应的索引。

相关内容

最新更新