我有一个项目,在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中(可能来自merge)。我们在.gitmodules中搜索git抱怨的路径,发现两个相同的部分。删除其中一个部分为我们解决了问题。

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

其他回答

当我使用SourceTree来做这些事情时,它会吐出这条消息。 我遇到的信息是:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree submodule update --init --recursive
No submodule mapping found in .gitmodules for path 'SampleProject/SampleProject'
Completed with errors, see above

我的场景是我错用了项目目录,包含。git文件夹。 SourceTree认为这个文件夹是git的子模块,但实际上不是。

我的解决方案是使用命令行删除它。

$ git rm -r SampleProject --cached
$ git commit -m "clean up folders"

清除git中的垃圾并保持清洁。

遵循rajibchowdhury的回答(被点了),使用git rm命令,建议删除索引中指示子模块的特殊条目(特殊模式为160000的“文件夹”)。

如果这个特殊的入口路径没有在.gitmodule中被引用(就像原始问题中的'Classes/Support/Three20'),那么你需要删除它,以避免“在.gitmodules for path中找不到子模块映射”错误消息。

你可以检查索引中所有引用子模块的条目:

git ls-files --stage | grep 160000

之前的回答(2010年11月)

有可能你没有正确地声明你的初始子模块(即没有任何结尾的'/',正如我以前的回答中所描述的,即使你的.gitmodule有看起来不错的路径)。

这个帖子提到:

当从一个新的克隆运行'git submodule init'时,你会得到相同的错误吗? 如果是这样,你就有问题了。 如果没有子模块,请删除.gitmodules,以及中对子模块的任何引用 .git/config,并确保Pikimal目录中没有.git目录。 如果这解决了问题,签入并在您的巡航工作副本上做同样的事情。

显然,不要删除你的主.gitmodules文件,但要照顾你工作树中其他额外的.gitmodules文件。


仍然在“不正确的子模块初始化”的主题中,Jefromi提到了实际上是gitlinks的子模块。

参见如何跟踪未跟踪的内容?以便将这样的目录转换为真正的子模块。

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

"path = thirdsrc\boost" 

"path = thirdsrc/boost", 

问题解决了!- -

有个问题。有一段时间,我尝试了删除路径的建议,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子模块命令,可能颠倒了参数。甚至可能是我……希望这能帮助到一些人!

我为自己解决了这个问题。一开始我是这么做的:

git submodule add --branch master [URL] [PATH_TO_SUBMODULE]

事实证明,如果你想克隆主分支,不应该使用——branch选项的规范。它抛出以下错误:

fatal: Cannot force update the current branch.
Unable to checkout submodule '[PATH_TO_SUBMODULE]'

每次你试着做

git submodule sync

这个错误将被抛出:

No submodule mapping found in .gitmodules for path '[PATH_TO_SUBMODULE]'

在.gitmodules中需要的行永远不会被添加。

所以我的解决方案是:

git submodule add [URL] [PATH_TO_SUBMODULE]