git 对于不是子模块的路径,在 .gitmodule 中找不到子模块映射

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4185365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:29:22  来源:igfitidea点击:

No submodule mapping found in .gitmodule for a path that's not a submodule

gitgit-submodules

提问by Ben Scheirman

I have a project that has a submodule at lib/three20

我有一个项目,其子模块位于 lib/three20

My .gitmodulefile looks like this:

我的.gitmodule文件看起来像这样:

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

I have cloned this in the past without errors, (git submodule initfollowed by a git submodule update) and it's been working for a while.

我过去没有错误地克隆了它,(git submodule init后跟 a git submodule update)并且它已经工作了一段时间。

I tried to clone this to a new machine, and now I'm getting this error on git submodule init:

我试图将它克隆到一台新机器上,现在我收到了这个错误git submodule init

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

That path is just an empty folder in Xcode that I use to house the projects from the other directory. It's not part of the .gitmodulesfile, so I don't see where it's getting this path from.

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

Any ideas?

有任何想法吗?

采纳答案by VonC

Following rajibchowdhury's answer(upvoted), use git rmcommand which is advised is for removing the special entryin the index indicating a submodule(a 'folder' with a special mode 160000).

按照rajibchowdhury回答(已投票),建议使用git rm命令删除索引中指示子模块(具有特殊模式的“文件夹” )的特殊条目160000

If that special entry pathisn't referenced in the .gitmodule(like 'Classes/Support/Three20' in the original question), then you need to remove it, in order to avoid the "No submodule mapping found in .gitmodulesfor path" error message.

如果该特殊条目路径未在.gitmodule(如Classes/Support/Three20原始问题中的“ ”)中引用,则您需要将其删除,以避免出现“.gitmodules路径中找不到子模块映射”错误消息。

You can check all the entries in the index which are referencing submodules:

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

git ls-files --stage | grep 160000


Previous answer (November 2010)

上一个答案(2010 年 11 月)

It is possible that you haven't declared your initial submodule correctly (i.e. without any tail '/' at the end, as described in my old answer, even though your .gitmodulehas paths which looks ok in it).

您可能没有正确声明您的初始子模块(即最后没有任何尾部“/”,如我的旧答案中所述,即使您的.gitmodule路径看起来不错)。

This threadmentions:

这个线程提到:

do you get the same error when running 'git submodule init' from a fresh clone?
If so, you have something wrong.

If you have no submodules, delete .gitmodules, and any references to submodules in .git/config, and ensure the Pikimal dir does not have a .gitdir in it.
If that fixes the problem, check in and do the same on your cruise working copy.

从新的克隆运行“git submodule init”时是否遇到相同的错误?
如果是这样,你有什么问题。

如果您没有子模块,请删除.gitmodules.git/config 中对子模块的任何引用,并确保 Pikimal 目录中没有.git目录。
如果这解决了问题,请检查并在您的巡航工作副本上执行相同操作。

Obviously, don't delete your main .gitmodulesfile, but look after other extra .gitmodulesfiles in your working tree.

显然,不要删除您的主.gitmodules文件,而要注意.gitmodules工作树中的其他额外文件。



Still in the topic of "incorrect submodule initialization", Jefromimentions submodules which actually are gitlinks.

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

See How to track untracked content?in order to convert such a directory to a real submodule.

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

回答by rajibchowdhury

No submodule mapping found in .gitmodules for path 'OtherLibrary/MKStore' when

在 .gitmodules 中找不到路径“OtherLibrary/MKStore”的子模块映射,当

$ git submodule update --init

I didn't know why the error occur. After spending a minute and found the answer in stackoverflow.

我不知道为什么会发生错误。花了一分钟后,在stackoverflow中找到了答案。

$ git rm --cached OtherLibrary/MKStore

and then update the submodule again. It's working fine.

然后再次更新子模块。它工作正常。

http://en.saturngod.net/no-submodule-mapping-found-in-gitmodules

http://en.saturngod.net/no-submodule-mapping-found-in-gitmodules

回答by Johnny

When I use SourceTree to do the stuff, it will spit out this message.
The message that I encountered:

当我使用 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

My scenario is I misapplied the project directory the contains .gitfolder.
SourceTree regarded this folder as git submodule, but actually not.

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

My solution is use command line to remove it.

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

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

remove the garbage in git and keep it clean.

清除git中的垃圾并保持干净。

回答by luksak

I resolved this issue for me. Initially I tried to do this:

我为我解决了这个问题。最初我尝试这样做:

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

As it turns out the specification of the --branch option should not be used if you want to clone the master branch. It throws this error:

事实证明,如果您想克隆 master 分支,则不应使用 --branch 选项的规范。它抛出这个错误:

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

Every time you try to do a

每次你尝试做一个

git submodule sync

This error will be thrown:

将抛出此错误:

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

And the lines needed in .gitmodules are never added.

.gitmodules 中所需的行永远不会添加。

So the solution for me was this:

所以我的解决方案是这样的:

git submodule add [URL] [PATH_TO_SUBMODULE]

回答by James Moore

I just hit this error after trying to "git submodule init" on a new checkout of my repo. Turns out I had specified the module sub-folder with the wrong case initially. Since I'm on a Mac with a case-sensitive filesystem (hurr) it was failing. For example:

我只是在尝试在我的 repo 的新结帐上“git submodule init”后遇到了这个错误。原来我最初用错误的情况指定了模块子文件夹。由于我在 Mac 上使用区分大小写的文件系统 (hurr),它失败了。例如:

git submodule add [email protected]:user/project.git MyApp/Resources/Project
Cloning into 'MyApp/Resources/Project'

succeeds but the trouble is that on disk the path is

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

Myapp/Resources/Project

What I don't understand is why git is init'ing the module to wrong folder (ignoring the incorrect case in my command) but then operating correctly (by failing) with subsequent commands.

我不明白的是,为什么 git 将模块初始化到错误的文件夹(忽略我的命令中的错误大小写),但随后的命令正确运行(失败)。

回答by hit9

Just git rm subdirwill be ok. that will remove the subdir as an index.

git rm subdir没事了。这将删除子目录作为索引。

回答by anomolos

Just had this problem. For a while I tried the advice about removing the path, git removing the path, removing .gitmodules, removing the entry from .git/config, adding the submodule back, then committing and pushing the change. It was puzzling because it looked like no change when I did "git commit -a" so I tried pushing just the removal, then pushing the readdition to make it look like a change.

刚遇到这个问题。有一段时间我尝试了关于删除路径、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 submodule update --init”,它会显示一条关于 git 不应再引用的特定名称的消息:存储库的名称,子模块是链接到的,而不是它检查到的路径名。Grepping 透露该引用位于 .git/index 中。所以我运行了“git rm --cached repo-name”,然后读取了模块。当我这次提交时,提交消息包含一个更改,即它正在删除这个意外的对象。之后它工作正常。

Not sure what happened, I'm guessing someone misused the git submodule command, maybe reversing the arguments. Could have been me even... Hope this helps someone!

不知道发生了什么,我猜有人误用了 git submodule 命令,也许是颠倒了参数。甚至可能是我......希望这对某人有所帮助!

回答by zhuzhai liu

in the file .gitmodules, I replaced string

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

"path = thirdsrc\boost" 

with

"path = thirdsrc/boost", 

and it solved! - -

它解决了!- -

回答by kenorb

The folder mapping can be found in .git/modulesfolder (each has configfile with reference to its worktree), so make sure these folders correspond to the configuration in .gitmodulesand .git/config.

该文件夹映射中可以找到.git/modules的文件夹(各自具有config文件参照其worktree),因此要确保这些文件夹对应于配置在.gitmodules.git/config

So .gitmoduleshas the correct path:

所以.gitmodules有正确的路径:

[submodule "<path>"]
  path = <path>
  url = [email protected]:foo/bar.git

and in .git/modules/<path>/configin [core]section you've the right path to your <path>, e.g.

.git/modules/<path>/config[core]部分你已经在正确的道路,以你的<path>,如

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

If the right folder in .git/modulesis missing, then you've to go to your submodule dir and try git reset HEAD --hardor git checkout master -f. If this won't help, you probably want to remove all the references to the broken submodule and add it again, then see: Rename a git submodule.

如果.git/modules缺少正确的文件夹,那么您必须转到子模块目录并尝试git reset HEAD --hardgit checkout master -f。如果这没有帮助,您可能希望删除对损坏的子模块的所有引用并再次添加,然后参见:重命名 git submodule

回答by ken

Scenario: changing the submodule from directory dirA-xxx to another directory dirB-xxx

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

  1. move the dirA-xxx to dirB-xxx
  2. modify entry in .gitmodules to use dirB-xxx
  3. modify entry in .git/config to use dirB-xxx
  4. modify .git/modules/dirA-xxx/config to reflect the correct directory
  5. modify dirA-xxx/.git to reflect the correct directory
  6. 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. :)

  1. 将 dirA-xxx 移动到 dirB-xxx
  2. 修改 .gitmodules 中的条目以使用 dirB-xxx
  3. 修改 .git/config 中的条目以使用 dirB-xxx
  4. 修改 .git/modules/dirA-xxx/config 以反映正确的目录
  5. 修改 dirA-xxx/.git 以反映正确的目录
  6. git submodule status

    如果返回错误:在 .gitmodules 中找不到路径 dirA-xxx 的子模块映射。这是因为 dirA-xxx 不存在,但它仍然被 git 跟踪。通过以下方式更新 git 索引:git rm --cached dirA-xxx

    尝试使用git submodule foreach git pull. git子模块结构我没有经过实际研究,所以上面的步骤可能会破坏一些东西。尽管如此,通过上述步骤,目前情况看起来不错。如果您有任何见解或正确的步骤来完成工作,请在此处分享。:)