我有一个项目,在lib/three20有一个子模块

我的.gitmodule文件是这样的:

[submodule "lib/three20"]
    path = lib/three20
    url = git://github.com/facebook/three20.git

我克隆了这个在过去没有错误,(git子模块init紧随git子模块更新),它已经工作了一段时间。

我试图克隆这个到一个新的机器,现在我在git子模块init上得到这个错误:

No submodule mapping found in .gitmodules for path 'Classes/Support/Three20'

这个路径只是Xcode中的一个空文件夹,我用它来存放来自另一个目录的项目。它不是.gitmodules文件的一部分,所以我不知道它从哪里得到这个路径。

什么好主意吗?


当前回答

在我的例子中,错误可能是由于两个分支上具有不同子模块配置的.gitmodules之间的错误合并。 在听取了这个论坛的建议后,我解决了手动编辑.gitmodules文件的问题,添加缺少的子模块条目非常容易。之后,命令 Git子模块update——init——递归 没有任何问题。

其他回答

文件夹映射可以在.git/modules文件夹中找到(每个文件夹都有参考其工作树的配置文件),因此确保这些文件夹对应于.gitmodules和.git/config中的配置。

因此.gitmodules有正确的路径:

[submodule "<path>"]
  path = <path>
  url = git@github.com:foo/bar.git

在[core]部分的.git/modules/<path>/config中,你有你的<path>的正确路径,例如。

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  worktree = ../../../<path>

如果在.git/modules中没有正确的文件夹,那么你必须去你的子模块目录并尝试git reset HEAD——hard或git checkout master -f。如果这没有帮助,你可能想删除所有对损坏子模块的引用,然后重新添加它,然后参见:重命名git子模块。

对我们来说,问题是重复的子模块条目被添加到.gitmodules中(可能来自merge)。我们在.gitmodules中搜索git抱怨的路径,发现两个相同的部分。删除其中一个部分为我们解决了问题。

值得注意的是,git 1.7.1给出了“没有子模块映射”的错误,但git 2.13.0似乎并不在意。

在查看了我的.gitmodules之后,我发现我确实在不应该出现的地方出现了一个大写字母。所以请记住,.gitmodules目录是区分大小写的

有个问题。有一段时间,我尝试了删除路径的建议,git删除路径,删除.gitmodules,从.git/config中删除条目,重新添加子模块,然后提交并推送更改。这是令人困惑的,因为当我做“git commit -a”时,它看起来没有变化,所以我试着只推删除,然后推读取,使它看起来像一个变化。

After a while I noticed by accident that after removing everything, if I ran "git submodule update --init", it had a message about a specific name that git should no longer have had any reference to: the name of the repository the submodule was linking to, not the path name it was checking it out to. Grepping revealed that this reference was in .git/index. So I ran "git rm --cached repo-name" and then readded the module. When I committed this time, the commit message included a change that it was deleting this unexpected object. After that it works fine.

不知道发生了什么,我猜有人误用了git子模块命令,可能颠倒了参数。甚至可能是我……希望这能帮助到一些人!

在.gitmodules文件中,我替换了字符串

"path = thirdsrc\boost" 

"path = thirdsrc/boost", 

问题解决了!- -