how to update submodule url in all commits

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

The Use Case is that i have to move certain repositories to a new server. So these repositories get a new url.
The Parent project which reference these sub-modules needs to be updated with the new url for the sub-module.
I think of doing the following.

  1. update the .gitmodules file
  2. git submodule sync
  3. git submodule update
  4. commit and push

But, since the previous commits have the earlier version of the .gitmodule, if i checkout a previous commit of the parent project - will it not look for the old server?


To ensure reproducibility, we need to have all old commits to be working. Any idea to get around this?

回答1:

The URL that's in .gitmodules is generally only used when initializing the submodules or on git submodule sync. On initialization (git submodule init), the URL is put into the repository's .git/config, and when the submodule is cloned into place (on git submodule update) the URL to use is taken from the config. The only other time the URL in .gitmodules is used is when you run git submodule sync, which will similarly update the URL in the config, but also set the origin remote in the submodule to the same URL.

This means that you won't have any problems with checking out an earlier commit and running git submodule update - the remote origin in your submodule isn't changed when you checkout a new commit in the parent repository.



回答2:

If you need to do that the only way to go is use filter-branch.

But be carefull because changing .gitmodules on all commits implies that you transform that commits.

If you have the git repo shared with a lot of developers all developers need to "force pull" the new commits and all work based on old commits need to be rebased to new branch.

There are a lot of discussions about rewriting git history.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!