Git 索引挂在旧的子模块路径上?

Git index Hanging on To Old Submodule Path?

我有一个包含两个子模块的存储库。 Git 在我 运行 git submodule initgit submodule update 时报错,出现以下错误:

fatal: no submodule mapping found in .gitmodules for path 'AppName.xcodeproj/..Vendor/AFNetworking'

我的子模块不在同一个目录中,我决定清理项目。我曾经有一个名为 Vendor 的目录,其中包含我的一些子模块,但我按照说明 here 从 git 中删除了子模块。然后,我将子模块重新添加到一个名为 submodules.

的新目录中

我的子模块之一是 AFNetworking 库,我已将其作为子模块添加到初始 Vendor 目录中。我刚才删除了它,并在清理过程中重新添加了它。该应用程序似乎构建得很好,我的 git submodule 命令运行正常。现在,当我在另一台机器上签出时,如上所述失败。

我的 .gitmodules 文件如下所示:

[submodule "submodules/AFNetworking"]
    path = submodules/AFNetworking
    url = https://github.com/AFNetworking/AFNetworking.git
[submodule "submodules/LNPopupController"]
    path = submodules/LNPopupController
    url = https://github.com/MosheBerman/LNPopupController.git

这似乎很正常,因为 git 知道我的模块在哪里,一切都应该很好。我的.git/config文件也是如此:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = git@github.com:MosheBerman/theshmuz.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[submodule "submodules/AFNetworking"]
    url = https://github.com/AFNetworking/AFNetworking.git

这个错误很微妙,我过了一段时间才意识到,但我注意到错误消息引用了 old Vendor 目录,没有不再存在。

我通过将 cat 的输出定向到文本文件并使用文本编辑器打开了 ./git/index。果然,索引中出现了AppName.xcodeproj/../Vendor/AFNetworking/。这会是一个糟糕的gitlink吗?我该如何清理它以便我可以正常初始化和构建我的回购协议?

我曾尝试从包含 AppName.xcodeproj 的根目录的索引中删除缓存引用,如下所示:

git rm --cached /Vendor/AFNetworking

因此,我重新创建了文件夹层次结构,并尝试在 /Vendor/AFNetworking. 中添加一个虚拟文件,我还尝试在 Vendor 中添加一个名为 "AFNetworking" 的文件。添加然后删除这些文件并没有起到作用。

我再次查看了这个问题,发现 a blog post (link) 解释了检查索引的正确方法。事实证明,我的索引中有对旧子模块的奇怪引用:

AppName.xcodeproj/../Vendor/AFNetworking.

解决方案是从索引中删除具有准确列表的文件,如下所示:

git rm --cached AppName.xcodeproj/../Vendor/AFNetworking

然后我就可以运行 git submodule update 成功了。看起来索引并不总是匹配 unix 文件系统的相对路径,但在某些情况下它可以更具体。 Pro Git 书中有一些信息(在第 9 章印刷版中,Chapter 10 online)让我怀疑这一点,但我花了博客 post 才明白如何打开索引。