【问题标题】:Added wrong git submodule and cannot change its origin添加了错误的 git 子模块并且无法更改其来源
【发布时间】:2018-12-22 13:48:45
【问题描述】:

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

git submodule add wrong-url project-directory

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

git submodule deinit -f project-directory

我尝试使用正确的网址添加它:

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 更改了远程网址,并使用git remote add right-url 添加了正确的网址,但这并没有帮助。

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

【问题讨论】:

    标签: git git-submodules


    【解决方案1】:

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

    git submodule deinit -f project-directory
    

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

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

    git rm -f project-directory
    

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

    rm -rf .git/modules/project-directory
    

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

    【讨论】:

    • 除了运行rm -rf .git/modules/project-directory之外,我还手动从.gitmodules中删除了该条目。然后就添加成功了。
    猜你喜欢
    • 2012-05-06
    • 2017-01-17
    • 2019-06-14
    • 1970-01-01
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    相关资源
    最近更新 更多