在子模块中git无法找到索引(“索引文件打开失败:不是目录”)

问题描述 投票:2回答:2

在一个新的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 [email protected]: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

git版本1.8.5.2在小牛队上运行

git git-submodules
2个回答
0
投票

那是因为父回购中还没有提交(意思是没有HEAD和no master branch)。 正如您所检测到的那样,父回购的GIT_DIR可能设置得太迟,无法使用子模块。 如果good bug to report涵盖那种情况,这将是一个none of the git submodule tests

或者,作为OP user3184153 commented

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


2
投票

我个人在我的预提交钩子中看到了这个问题,因为某些子模块自动化。环境变量GIT_DIRGIT_WORK_TREEGIT_INDEX_FILE等引起了这个问题。我能用env -i git <git-command>修复这个问题,这是一个使用单个命令使用干净的bash环境的简单方法。

© www.soinside.com 2019 - 2024. All rights reserved.