如何在所有提交中更新子模块URL [英] how to update submodule url in all commits
问题描述
用例是我必须将某些存储库移至新服务器.因此,这些存储库将获得一个新的URL.
引用这些子模块的父项目需要使用该子模块的新URL进行更新.
我想做以下事情.
- 更新.gitmodules文件
- git子模块同步
- git子模块更新
- 提交并推送
但是,由于先前的提交具有.gitmodule的早期版本,如果我签出父项目的先前的提交-它将不寻找旧服务器吗?
为了确保可重复性,我们需要所有旧提交都可以正常工作.
有解决这个问题的想法吗?
.gitmodules
中的URL通常仅在初始化子模块时或在git submodule sync
上使用.初始化(git submodule init
)时,将URL放入存储库的.git/config
中,并且将子模块克隆到位(在git submodule update
上)时,要使用的URL从配置中获取.使用.gitmodules
中的URL的唯一其他时间是您运行git submodule sync
时,这将类似地更新配置中的URL,但还将子模块中的origin
远程设置为相同的URL.
这意味着您签出先前的提交并运行git submodule update
不会有任何问题-在父存储库中签出新的提交时,子模块中的远程origin
不会更改.>
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?
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.
这篇关于如何在所有提交中更新子模块URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!