-1

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

我的工作流程:

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

  5. 使用提交 A、B、C 克隆 repo

  6. 切换到提交 A
  7. git submodule update --init -> 失败

-> 还想要新的子模块远程 URL,但仍然是 .gitmodules 中的旧 url

似乎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.

4

2 回答 2

1

让我们尝试另一种方法。而不是替换配置文件中的 URL,而是动态替换 URL:

git config --global url.<NEW-URL>.insteadOf <OLD-URL>

git help configurl.<base>.insteadOf

于 2020-04-26T17:16:09.897 回答
0

提交与远程无关。一旦您更改了遥控器,该更改对所有新旧提交都有效。

要更改子模块的 URL,您需要:

  • 更改.gitmodules超级项目根目录下文件中的 URL;
  • 运行git submodule sync以将更改复制到.git/config
  • cd进入子模块并运行git remote set-url以更改子模块中的 URL。

当您在超级项目中签出旧提交时,您会变老.gitmodules,但这没关系——git不使用来自的 URL——.gitmodules它使用来自.git/config. git sync将 URL 从 复制.gitmodules.git/config.gitmodules因此,在使用旧的“请勿运行”签出旧提交后git syncgit将继续使用来自.git/config.

于 2020-04-26T11:42:27.087 回答