gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:15:33 25 4
gpt4 key购买 nike

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

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

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

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

我的 .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 吗?我该如何清理它以便我可以正常初始化和构建我的 repo 协议(protocol)?

最佳答案

我曾尝试从包含 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)让我怀疑这一点,但我通过博客文章才明白如何打开索引。

关于Git 索引卡在旧的子模块路径上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38687028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com