gpt4 book ai didi

git - 为什么我不能在删除后添加回 git 子模块

转载 作者:太空狗 更新时间:2023-10-29 13:38:24 25 4
gpt4 key购买 nike

我尝试删除一个子模块,然后使用 git 1.8.5.2 将其添加回来。子模块 asubgit 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.

我不确定这条错误信息是什么意思。我还尝试在 super 项目中执行 git submodule sync,并尝试过

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

但我仍然无法添加子模块。我错过了什么,或者这是 git 1.8.5.2 中的错误?

我想这样做的原因是 a) 删除一个子模块,b) 将其添加回去,以便它反射(reflect)子模块的最新内容。这听起来可能很天真,但我发现 submodule add -b 功能将在我克隆 super 项目 (how to keep git submodule on-branch status after cloning superproject?) 后立即中断。所以我想一个简单的方法可以避免让子模块跟踪它们的主分支的所有麻烦,就是每次克隆 super 项目时删除子模块并将其添加回来。

最佳答案

经过一番greping后发现

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

需要第三步:

rm -f .git/modules/asub

显示错误消息是因为 .git/modules/asub 保留在 git rm 之后,并在删除子目录后消失。现在子模块 asub 可以按我喜欢的任何方式添加回来。

关于git - 为什么我不能在删除后添加回 git 子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20961885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com