可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
- update the .gitmodules file
- git submodule sync
- git submodule update
- 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.