[英]Changing the remote repository of git submodule for all commits in git history
如何在不破坏提交历史记录的情况下更改 git 子模块的远程 url? 目前,如果我检查旧提交,我的子模块似乎不再存在旧的远程 url 女巫。
我的工作流程:
Push.gitmodules 到远程(提交 C)
使用提交 A、B、C 克隆存储库
-> 还想要新的子模块远程 URL,但仍然是旧的 url in.gitmodules
看来git submodule update --init
仍在尝试使用旧的远程 url
如果还按照建议尝试使用git submodule update
,但我也得到了错误:
The Git repository with name or identifier OLD_REPO_NAME does not exist or you do not have permissions for the operation you are attempting.
让我们尝试另一种方法。 而不是替换配置文件中的 URL,而是动态替换 URL:
git config --global url.<NEW-URL>.insteadOf <OLD-URL>
请参阅git help config
url.<base>.insteadOf
。
提交与远程无关。 一旦您更改了遥控器,该更改对所有新旧提交都有效。
要为您需要的子模块更改 URL:
.gitmodules
;git submodule sync
将更改复制到.git/config
cd
进入子模块并运行git remote set-url
以更改子模块中的 URL。 当您在超级项目中签出旧提交时,您会得到旧的.gitmodules
但这没关系git
不使用来自 .gitmodules 的.gitmodules
它使用来自.git/config
的 URL。 git sync
将 URL 从.gitmodules
复制到.git/config
。 因此,在使用旧的.gitmodules
签出旧提交后,请勿运行git sync
,并且git
将继续使用来自.git/config
的新 URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.