为什么我在移除git子模块后无法重新添加它?

5
我尝试使用git 1.8.5.2删除一个子模块,然后再添加回来。 一个子模块asub是通过git submodule add -b master url_asub.git添加的。 我通过以下方式删除了该子模块:

git rm asub

asub目录已经不存在了。然后我尝试使用原始命令再次添加它(以测试1.8.5.2中的子模块删除是否干净):

git submodule add -b master url_asub.git

我收到了一个错误信息:

A git directory for 'asub' is found locally with remote(s): 
   origin url_asub.git
If you want to reuse this local git directory instead of cloning again from
   url_asub.git 
use the '--force' option. If the local git directory is not the
correct repo or you are unsure what this means choose another name with the
'--name' option.

我不确定这个错误信息的含义。我还尝试在超级项目中执行git submodule sync,并尝试过。
git submodule deinit asub
git rm asub
git submodule add -b master url_asub.git

但是我仍然无法添加子模块。我错过了什么,或者这是git 1.8.5.2的一个bug吗?
我想做的原因是a)删除子模块并b)重新添加它,以便反映子模块最新的内容。这可能听起来很天真,但我发现submodule add -b功能将在我克隆超级项目(how to keep git submodule on-branch status after cloning superproject?)后立即中断。所以我想也许一个简单的方法来避免所有保持子模块跟踪其主分支的麻烦就是每次在克隆超级项目时删除子模块并重新添加它。
2个回答

5

经过一些搜索,我发现在

git submodule add -b master url_asub.git
git rm asub

需要进行第三步操作:
rm -f .git/modules/asub

错误信息显示是因为在执行git rm命令后,.git/modules/asub目录仍然存在,删除子目录后错误消失。现在可以以任何方式重新添加子模块asub

1
如果你只是删除了文件,那么执行 git submodule update 命令会重新拉取它们。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接