【问题标题】:git failing to find the index when in submodule ("index file open failed: not a directory")git 在子模块中找不到索引(“索引文件打开失败:不是目录”)
【发布时间】:2014-01-11 03:57:26
【问题描述】:

在新的 git repo 上,添加子模块并更改到子模块目录后,大多数 git 命令在子模块中运行时都会失败并出现错误:

fatal: index file open failed: Not a directory

重现问题的完整命令集:

>  git init .
Initialized empty Git repository in /Users/drh/code/personal/Experiments/git-test/.git/
>  git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)
>  git submodule add git@github.com:mitsuhiko/flask.git thirdparty/flask
Cloning into 'thirdparty/flask'...
remote: Reusing existing pack: 9959, done.
remote: Total 9959 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (9959/9959), 5.17 MiB | 1.11 MiB/s, done.
Resolving deltas: 100% (5617/5617), done.
Checking connectivity... done.
>  cd thirdparty/flask
>  git status
fatal: index file open failed: Not a directory
>  cat .git
gitdir: ../../.git/modules/thirdparty/flask

在 Mavericks 上运行的 git 版本 1.8.5.2

【问题讨论】:

  • 只是为了实验......我尝试将.git符号链接到正确的目录(../../.git/modules/thirdparty/flask),这解决了索引文件打开失败的直接问题,但它似乎与 git 如何检测子模块的脏状态并可能有其他负面影响
  • 解决了这个问题。为了关闭其他人的循环,这是通过打开一个新的终端会话来解决的。我怀疑这是一些 git 环境变量(可能是 GIT_DIR)的某种奇怪状态。

标签: git git-submodules


【解决方案1】:

我个人在一些子模块自动化的预提交挂钩中看到了这个问题。环境变量GIT_DIRGIT_WORK_TREEGIT_INDEX_FILE 等导致了这个问题。我可以使用 env -i git <git-command> 解决这个问题,这是一种通过单个命令使用干净 bash 环境的简单方法。

【讨论】:

    【解决方案2】:

    那是因为父 repo 中还没有提交(意味着没有 HEAD 和 no master branch)。
    正如您所检测到的,父 repo 的 GIT_DIR 可能设置得太晚,子模块无法使用。
    如果none of the git submodule tests 涵盖该场景,那将是good bug to report

    或者,作为OP user3184153 commented

    我认为其他一些应用程序(我怀疑 virtualenv,虽然无法重现)正在设置 GIT_DIR

    【讨论】:

    • 嗯,感谢您的帮助,虽然我只是用一个新的 repo 尝试了这个,即使在父 repo 中没有提交它也确实有效。我认为其他一些应用程序(我怀疑 virtualenv,虽然无法重现)正在设置 GIT_DIR
    • @user3184153 好的。为了提高知名度,我已将您的结论包含在答案中。
    猜你喜欢
    • 2013-02-21
    • 2021-09-13
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 2012-04-30
    • 1970-01-01
    相关资源
    最近更新 更多