添加了错误的 git 子模块且无法更改其来源

Added wrong git submodule and cannot change its origin

我在我的 git 超级项目中添加了一个新的子模块:

git submodule add wrong-url project-directory

这是一个错误的项目,因此我已将其删除:

git submodule deinit -f project-directory

我尝试用右url:

添加
git submodule add right-url project-directory

不幸的是它产生了一个错误:already exists in the index.

我发现这个可以解决问题: Issue with adding common code as git submodule: "already exists in the index"

因此,我 运行 这些命令:

git rm --cached project-directory
git rm -r --cached project-directory

但是,正如 in this comment 所述,我收到了错误消息 project-directory already exists and is not a valid git repo。这样我就删除了project-directoryproject-directory添加成功了。

问题是内容链接到 wrong-url

我已经编辑了.gitmodules(其中url是错误的),结果是一样的。

我还使用 git remote rm origin 更改了遥控器 url 并使用 git remote add right-url 添加了正确的 url,但它没有帮助。

我很好奇这个错误的远程 url 存储在哪里,我该如何解决这个问题?

It was a wrong project, therefore I have removed it:

git submodule deinit -f project-directory

这将从 .git/config 中删除条目并清除项目目录内容。

但是,.gitmodules 文件中的条目仍然完好无损。要摆脱它,只需从 git 中删除现在为空的目录,它会自动清除该条目:

git rm -f project-directory

最后,您应该删除子模块的实际 git 目录,位于 .git/modules:

rm -rf .git/modules/project-directory

就是这样,应该没有子模块的痕迹,你可以添加正确的。