我正在尝试添加一个已经存在的子模块(不同的 git 远程存储库)。由于我之前没有搜索过如何正确执行此操作,我想我弄乱了我的存储库,我需要一些帮助来重新修复它。
我已经从 .gitmodules 和 .git/config 中删除了关于我要删除的子模块的所有相关部分。我还验证了我的 .git/目录中没有模块目录。
但是,当我运行命令 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
最佳答案
显示消息('repo' 已存在于索引中
)的唯一方法是如果'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
' 不是子模块,如果它存在,它也会阻止声明同名的子模块。
关于git - 添加一个无法从索引中删除的子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12218420/