我有一个项目,在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文件的一部分,所以我不知道它从哪里得到这个路径。

什么好主意吗?


当前回答

通常,git会在项目的根目录(.git/)中创建一个隐藏目录。

当你在CMS上工作时,你可能会安装带有.git/目录的模块/插件,其中包含特定模块/插件的git元数据

最快的解决方案是找到所有的.git目录,只保留根git元数据目录。如果这样做,git将不会将这些模块视为项目子模块。

其他回答

没有找到子模块路径'path/to/submodule'的url 在.gitmodules中没有找到路径'path/to/submodule'的子模块映射

当我从根目录文件夹“cd”到。/resources/css/style.css时,这些错误就开始了。

我使用git init从style.css,认识到我的错误后,我已经添加 Git添加remote origin <url>。

所以,仍然在git bash中的style.css文件中,我使用git删除远程原点。

当我检查git remote时,远程链接已被删除。

Ultimately, after doing git init for the root directory, adding it to remote, the resources/css path was providing the submodule error/fatal errors listed up top. So, from the root directory, in git bash, I typed git rm --cached resources/css, deleted the css directory (saved the code), pushed the changes, and added a css directory and styles.css file within it in a different branch (optional) to see how the outcome would be after pushing changes again and checking the deployment on github pages. It worked! I know deleting directories isn't always ideal, especially in large projects, but just wanted to share one more way to fix this issue!

ps相当新的stackoverflow,所以我为冗长的文本道歉。 # 2022的答案

我刚刚在尝试“git子模块初始化”后遇到了这个错误,在我的回购的新签出。原来我最初用错误的大小写指定了模块子文件夹。因为我用的是区分大小写的Mac文件系统(hurr),所以它失败了。例如:

git submodule add git@github.com:user/project.git MyApp/Resources/Project
Cloning into 'MyApp/Resources/Project'

成功,但问题是在磁盘上的路径是

Myapp/Resources/Project

我不明白的是,为什么git将模块初始化到错误的文件夹(忽略我命令中的不正确情况),但随后使用后续命令正确操作(失败)。

场景:将子模块从目录dirA-xxx更改为另一个目录dirB-xxx

move the dirA-xxx to dirB-xxx modify entry in .gitmodules to use dirB-xxx modify entry in .git/config to use dirB-xxx modify .git/modules/dirA-xxx/config to reflect the correct directory modify dirA-xxx/.git to reflect the correct directory run git submodule status if return error: No submodule mapping found in .gitmodules for path dirA-xxx. This is due to dirA-xxx is not existing, yet it is still tracked by git. Update the git index by: git rm --cached dirA-xxx Try with git submodule foreach git pull. I didn't go through the actual study of git submodule structure, so above steps may break something. Nonetheless going through above steps, things look good at the moment. If you have any insight or proper steps to get thing done, do share it here. :)

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

文件夹结构

xyz folder as root directory which contains 2 folder as submodule
  -- product
  -- user

从根目录执行以下命令

git rm --cached product/
git rm --cached user/

进入产品目录并执行

 git submodule update --init

进入用户目录并执行

git submodule update --init

再次进入根目录CD ..

git add --all