添加无法从索引中删除的子模块

时间:2012-08-31 15:29:49

标签: git git-submodules

我正在尝试添加一个已经存在的子模块(不同的git远程存储库)。由于我没有在如何正确地进行搜索之前进行搜索,我认为我已经弄乱了我的存储库,我需要一些帮助才能再次修复它。

我已经删除了.gitmodules和.git / config中有关我要删除的子模块的所有相关部分。我还验证了.git /目录中没有modules目录。

但是,当我运行命令git rm --cached path_to_submodule时,会显示以下消息:

fatal: pathspec 'path_to_submodule' did not match any files

由于上一个命令失败,当我尝试再次使用新定义添加相同的子模块时,运行命令git submodule add gituser@host:repo.git,这是显示的消息:

'repo' already exists in the index

5 个答案:

答案 0 :(得分:44)

可以显示消息('repo' already exists in the index)的唯一方法是,索引中是否仍存在“repo”(请参阅​​this chapter on submodule):

$ rm -Rf rack/
$ git submodule add git@github.com:schacon/rack.git rack
'rack' already exists in the index

You have to unstage the rack directory first. Then you can add the submodule:

$ git rm -r rack
$ git submodule add git@github.com:schacon/rack.git rack

即使'rack'不是子模块,如果它存在,也会阻止声明同名的子模块。

答案 1 :(得分:4)

如果添加新子模块的输出是:

'FolderName' already exists in the index

提示下一个命令

git ls-files --stage 

输出类似于:

160000 d023657a21c1bf05d0eeaac6218eb5cca8520d16  0  FolderName

然后,删除文件夹索引提示:

git rm -r --cached FolderName

再次尝试添加子模块

答案 2 :(得分:1)

可能发生,合并错误,手动删除子模块的文件夹或其他内容,如Hallileo Comet

    文件.gitmodules中的
  1. - 删除子模块的链接(包含子模块名称的整个部分)

  2. 文件.git\config中的
  3. - 删除子模块的链接,如上一步

  4. 文件夹.git\modules中的
  5. - 删除相对路径类似于“问题”模块的相对路径的文件夹

  6. 确保子模块的文件夹不再存在

  7. 然后:

    $ git submodule add -f --name <name> <git://path_1.git> <path_2>

    其中:name - 您希望的子模块的名称,可以等于您的repo名称; - 子模块源代码库的路径(即-github等), - 子模块所在文件夹的相对路径

    这允许你在路径中添加子模块或者在索引中仍然存在的名称,但不能自然地存活。

  8. 我没有找到任何方法从索引中删除这些死链接,但是在强制

答案 3 :(得分:0)

&#39;子模块/ uasdk-CLIB&#39;已存在于索引

git rm -r --cached submodules / uasdk-clib

git submodule add -b china / release / 16.8.0 -f ssh://git@xxx-ios-uasdk.git submodules / uasdk-clib

答案 4 :(得分:0)

这是因为您的存储库中的文件夹与子模块的名称相同

$ git rm -r subModuleName
$ git submodule add "your submodule repo path without these quotes"

再试一次添加子模块

相关问题