繁体   English   中英

为 git 历史记录中的所有提交更改 git 子模块的远程存储库

[英]Changing the remote repository of git submodule for all commits in git history

如何在不破坏提交历史记录的情况下更改 git 子模块的远程 url? 目前,如果我检查旧提交,我的子模块似乎不再存在旧的远程 url 女巫。

我的工作流程:

  1. 使用提交 A,B 克隆 repo
  2. git子模块更新--init
  3. 更改子模块 url
  4. Push.gitmodules 到远程(提交 C)

  5. 使用提交 A、B、C 克隆存储库

  6. 切换到提交 A
  7. git 子模块更新--init -> FAILES

-> 还想要新的子模块远程 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 文件中的.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM