How to update submodule url in all commits

The use case is that I need to move some repositories to a new server. Thus, these repositories get a new URL. The parent project that references these submodules needs to be updated with the new URL for the submodule.
I am thinking of doing the following.

  • update the .gitmodules file
  • git submodule synchronization
  • git submodule update
  • commit and click

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


To ensure reproducibility, we need all the old commits to work. Any idea to get around this?

+4
source share
2 answers

The URL that .gitmodules normally uses only when initializing submodules or on git submodule sync . During initialization ( git submodule init ), the URL is placed in the .git/config repository, and when the submodule is cloned into place (on git submodule update ), the URL to be used is taken from the config. The only time a .gitmodules used is when you run git submodule sync , which similarly updates the URL in the config, and also removes the origin remote in the submodule with the same URL.

This means that you will not have problems checking an earlier commit and running git submodule update - the remote origin in your submodule will not be changed when checking for a new commit in the parent repository.

+9
source

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

But be careful , because changing .gitmodules on all commits means you are converting this.

If you have a git repo shared with a large number of developers, all developers need to "force pull" new commits and execute everything based on old commits, you must reinstall them in a new branch.

There is a lot of discussion about rewriting git history.

0
source

All Articles