如果'/'是存储库的根目录,为什么git会中断?

lar*_*sks 6 git version-control configuration system

我们想使用git来维护系统配置.因为有时配置数据存在于/ etc之外,我们已经开始在我们的系统上做这样的事情了:

  # cd /
  # git init
  # git add etc
  # git add some/other/path
  # git commit -m 'initial import'
Run Code Online (Sandbox Code Playgroud)

等等.这很有效.只要你的cwd =='/',git就能正常运行.但是,例如,如果您尝试从子目录中运行git:

cd /etc
git status
Run Code Online (Sandbox Code Playgroud)

你得到了垃圾.在我们的例子中,成千上万行的"已删除:"列表显然仍然存在.此行为似乎是在/中运行git所独有的.在其他地方做同样的事情就可以了.

我可以"修复"这样的行为:

GIT_WORK_TREE=/ git status
Run Code Online (Sandbox Code Playgroud)

嘿,一切都按照Linus的意图行事......但这是一种痛苦.我不想单方面在环境中设置它(因为这会与在其他存储库中使用git冲突),并且我想避免使用包装器脚本.我还有其他选择吗?

lar*_*sks 3

在存储库上设置core.worktree选项可以很好地解决这个问题:

git config core.worktree /
Run Code Online (Sandbox Code Playgroud)

这比在环境中设置 GIT_WORK_TREE 效果要好得多。耶!