如何在所有提交中更新子模块URL [英] how to update submodule url in all commits

查看:102
本文介绍了如何在所有提交中更新子模块URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用例是我必须将某些存储库移至新服务器.因此,这些存储库将获得一个新的URL.
引用这些子模块的父项目需要使用该子模块的新URL进行更新.
我想做以下事情.

  1. 更新.gitmodules文件
  2. git子模块同步
  3. git子模块更新
  4. 提交并推送

但是,由于先前的提交具有.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.

  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?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆