git 添加无法从索引中删除的子模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12218420/
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
Add a submodule which can't be removed from the index
提问by Rui Gon?alves
I'm trying to add a submodule that already existed (different git remote repository). As I didn't searched before how to do it correctly, I think I've messed up my repository and I need some help to fix it again.
我正在尝试添加一个已经存在的子模块(不同的 git 远程存储库)。由于我在如何正确执行之前没有进行搜索,因此我认为我弄乱了我的存储库,我需要一些帮助来再次修复它。
I've already deleted all the relevant sections from the .gitmodules and .git/config regarding the submodules I want to delete. I've also verified that there is not modules directory inside my .git/ directory.
我已经从 .gitmodules 和 .git/config 中删除了关于我想要删除的子模块的所有相关部分。我还验证了我的 .git/ 目录中没有模块目录。
However, when I run the command git rm --cached path_to_submodule
, the following message is displayed:
但是,当我运行命令时git rm --cached path_to_submodule
,会显示以下消息:
fatal: pathspec 'path_to_submodule' did not match any files
As the previous command fails, when I try to add again the same submodule with the new definitions, running the command git submodule add gituser@host:repo.git
, this is the displayed message:
由于上一个命令失败,当我尝试再次添加具有新定义的相同子模块时,运行命令git submodule add gituser@host:repo.git
,这是显示的消息:
'repo' already exists in the index
回答by VonC
The only way that message ('repo' already exists in the index
) can be displayed is if 'repo' still exists in the index (see this chapter on submodule):
'repo' already exists in the index
可以显示消息 ( )的唯一方法是如果索引中仍然存在“repo”(请参阅有关 submodule 的本章):
$ rm -Rf rack/
$ git submodule add [email protected]: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 [email protected]:schacon/rack.git rack
Even if 'rack
' isn't a submodule, if it exists, it would prevent the declaration of a submodule of the same name.
即使 ' rack
' 不是子模块,如果它存在,它也会阻止同名子模块的声明。
回答by GutiMac
If the output adding a new submodule is:
如果添加新子模块的输出是:
'FolderName' already exists in the index
Tip the next commands
提示下一个命令
git ls-files --stage
The output will be something similar to:
输出将类似于:
160000 d023657a21c1bf05d0eeaac6218eb5cca8520d16 0 FolderName
Then, to remove the folder index tip:
然后,删除文件夹索引提示:
git rm -r --cached FolderName
Try again add the submodule
再次尝试添加子模块
回答by SynCap
May occur, when merging with error, manual deleting of folder of submodule, or something else, like Hallileo Comet
可能会发生在合并错误、手动删除子模块的文件夹或其他东西时,例如 Hallileo Comet
in file
.gitmodules
- delete links to submodule (whole section with submodule name)in file
.git\config
- delete links to submodule, as in previous stepin folder
.git\modules
- delete folder with relative path similar to relative path of "problem" moduleensure, that folder of submodule is not exists anymore
then:
$ git submodule add -f --name <name> <git://path_1.git> <path_2>
where: name - name of submodule as u wish, may be equal your
repo
name; - path to submodule source repo (ie - github, etc), - relative path to folder where submodule will residethis lets u to add submodule within path or with name which still present in index, but not naturally alive.
在文件中
.gitmodules
- 删除到子模块的链接(带有子模块名称的整个部分)在文件中
.git\config
- 删除到子模块的链接,如上一步在文件夹中
.git\modules
- 删除相对路径类似于“问题”模块相对路径的文件夹确保,子模块的文件夹不再存在
然后:
$ git submodule add -f --name <name> <git://path_1.git> <path_2>
其中: name - 您希望的子模块名称,可能与您的
repo
名字相同;- 子模块源代码库的路径(即 - github 等), - 子模块所在文件夹的相对路径这让您可以在路径中或名称中添加子模块,这些子模块仍然存在于索引中,但不是自然存在的。
i didn't found any method to remove these dead links from index, but when forced
我没有找到任何方法从索引中删除这些死链接,但是当被迫时
回答by knight2016
'submodules/uasdk-clib' already exists in the index
'submodules/uasdk-clib' 已经存在于索引中
git rm -r --cached submodules/uasdk-clib
git rm -r --cached 子模块/uasdk-clib
git submodule add -b china/release/16.8.0 -f ssh://[email protected] submodules/uasdk-clib
git submodule add -b china/release/16.8.0 -f ssh://[email protected] submodules/uasdk-clib
回答by abhishek tomer
this is because you have the folder in your repo same name as the name of your submodule
这是因为您的 repo 中的文件夹与子模块的名称相同
$ git rm -r subModuleName
$ git submodule add "your submodule repo path without these quotes"
Try again adding the submodule
再次尝试添加子模块