Linux和Windows的Git子模块

Linux和Windows的Git子模块,git,git-submodules,Git,Git Submodules,在Linux上使用git子模块时,我可能会有一个.gitmodules,其中一个或多个子系统是从/mnt/gitrepos/subsystemm1.git(基于中心文件的访问)中签出的 我还希望支持Windows用户,他们可以从H:/gitrepos/subsystemm1.git/访问相同的模块repo 例如,它是来自Linux的Samba共享,/mnt/gitrepos/作为共享gitrepos Git是否有办法根据操作系统处理URL行? 对于Windows,.gitmodules将是 [s

在Linux上使用
git子模块
时,我可能会有一个
.gitmodules
,其中一个或多个子系统是从
/mnt/gitrepos/subsystemm1.git(基于中心文件的访问)中签出的

我还希望支持Windows用户,他们可以从
H:/gitrepos/subsystemm1.git/
访问相同的模块repo

例如,它是来自Linux的Samba共享,
/mnt/gitrepos/
作为共享
gitrepos

Git是否有办法根据操作系统处理URL行? 对于Windows,
.gitmodules
将是

[submodule "subsystem1"]
  path = subsystem11
  url = H:/gitrepos/subsystem1.git/
因此,我希望对
.gitmodules
(推测语法)使用“类似”的通用代码:


不需要。子模块通常是为一个在任何地方都能工作的存储库URL而设计的,通常是基于网络的(例如
git://host/path
)。没有为一个存储库提供多个不同URL的机制


也就是说,Git确实允许您自定义子模块的URL。初始化子模块时(
git submodule init
),将
.gitmodules
中的URL复制到
.git/config
文件中。现在,您可以在运行
git submodule update

之前编辑那里的URL。我考虑(但没有尝试)的一个解决方法是将子模块代码库(“在您的示例中为subsystem1.git”)初始化为独立的本地存储库。在子模块中添加一个“remote”,它指向存储库的独立本地版本。还可以在子系统存储库的非子模块(独立、本地)版本中添加一个“remote”,该版本指向子模块版本。然后,您应该能够使用Samba/Windows/Linux更新subsystemm1.git的独立(非子模块)版本,然后从子模块内“git fetch independent”将代码从非子模块存储库复制到子模块存储库

最后,您的目录结构应该如下所示:

/mnt/gitrepos/
/mnt/gitrepos/subsystem1.git/
/mnt/subsystem1.git/
每个存储库中的远程设备如下所示:

/mnt/gitrepos/.git/config would have one remote block:
    [remote "origin"]   (points to your main, non-local repository)
/mnt/subsystem1.git/.git/config would have two remote blocks:
    [remote "origin"]   (points to your main, non-local repository)
    [remote "local_origin"]   (points to /mnt/gitrepos/subsystem1.git)
/mnt/gitrepos/.git/modules/subsystem1.git/config would also have two remote blocks:
    [remote "origin"]   (points to your main, non-local repository)
    [remote "independent"]   (points to /mnt/subsystem1.git)
将子模块的代码与远程服务器上的代码同步将成为一个多步骤的过程,因为您必须使用“独立”存储库作为中间存储库/暂存区域


您的里程可能会有所不同。。。这只是一个看起来应该有效的东西,而不是我尝试过的东西。

这就是为什么子模块有两个阶段的初始化-允许在实际克隆子模块之前在本地存储库中更改url。很好!很好的解释。我可以在“git submodule init”和“git submodule update--recursive”之间添加一个转换器脚本
/mnt/gitrepos/
/mnt/gitrepos/subsystem1.git/
/mnt/subsystem1.git/
/mnt/gitrepos/.git/config would have one remote block:
    [remote "origin"]   (points to your main, non-local repository)
/mnt/subsystem1.git/.git/config would have two remote blocks:
    [remote "origin"]   (points to your main, non-local repository)
    [remote "local_origin"]   (points to /mnt/gitrepos/subsystem1.git)
/mnt/gitrepos/.git/modules/subsystem1.git/config would also have two remote blocks:
    [remote "origin"]   (points to your main, non-local repository)
    [remote "independent"]   (points to /mnt/subsystem1.git)