移动 Git 子模块时,如何使用子模块的新 URL 更新父存储库中的完整历史记录?

问题描述

谁能帮帮我。 我想将一些 Git 存储库从一台服务器移动到另一台服务器,并同时重命名它们。 我遇到的问题是当某些存储库是其他存储库的子模块时。我想在顶级模块中所有分支的整个历史记录中替换子模块的 URL,这样一旦删除了原件,我仍然可以返回并重建旧的提交。 我使用的是 Windows PC,目前我正在使用 .bat 文件来运行我的存储库迁移。

要将子模块从 server1 移动到 server2 并将名称从 sub_old 更改为 sub_new 我将原始(裸)克隆到我的 C: 驱动器上的文件夹中,更改 URL,然后推送到新服务器:

git clone --bare https://server1/sub_old.git c:\temp_repo
cd c:\temp_repo
git remote set-url origin https://server2/sub_new.git
git push --mirror

然后从 server1 中删除 sub_old。

现在,当我想将使用 sub_old 存储库作为子模块的顶级存储库移动到新服务器时:

git clone --bare https://server1/top_old.git c:\temp_repo
cd c:\temp_repo
git remote set-url origin https://server2/top_new.git
REM At this point I want to change all of the references to the submodule from https://server1/sub_old.git to https://server2/sub_new.git
git push --mirror

然后从 server1 中删除 top_old。

在我想更改对子模块的所有 URL 引用时,我尝试使用:

git config --global url.https://server2/sub_new.git.insteadOf https://server1/sub_old.git

但没有成功。 我显然不明白这应该如何工作,或者它是否适合使用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)