克隆带有嵌套子模块的存储库不起作用 [英] cloning a repo with nested submodules does not work

查看:421
本文介绍了克隆带有嵌套子模块的存储库不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个单独的git repos,其中没有子模块.任务是组装这些存储库的层次结构树,并使用它在用户之间共享.这对于'subtree'或'subrepo'方案来说是微不足道的,但似乎不适用于'submodules'.尝试子模块的原因是nfs系统上的git性能缓慢.就我而言,结帐需要2个小时以上

I have multiple separate git repos which have no submodules in them. The task is to assemble a hierarchical tree of those repos and use it to share between users. This is trivial with 'subtree' or 'subrepo' schemes, but it seems not to work with 'submodules'. The reason to try submodules is slow git performance on the nfs systems. In my case checkout takes more than 2 hours

我正在尝试创建一个包含子模块的共享存储库.到目前为止,第一次克隆尝试失败.这是测试用例:

I am trying to create a shared repo which contains submodules. So far the very first attempt to clone fails. Here is the test case:

 mkdir m1 ; cd m1 ; git init ; date > a.txt ; git add --all ; git commit -m added ; cd -
 mkdir m2 ; cd m2 ; git init ; date > b.txt ; git add --all ; git commit -m added ; cd -
 mkdir m3 ; cd m3 ; git init ; date > c.txt ; git add --all ; git commit -m added ; cd -
 mkdir msub; cd msub; git init; date > d.txt; git add --all; git commit -m added;
 git submodule add `realpath ../m1` m1
 cd m1
 git submodule add `realpath ../../m2` m2
 git submodule add `realpath ../../m3` m3
 git commit -m 'added submodules'
 cd ..
 git commit -m 'added a submodule'
 cd ..
 git clone --recursive msub msub1

结果是,它使用单个顶级子模块(m1)创建了msub1.

As a result it creates msub1 with a single top-level submodule (m1).

在其他情况下,在克隆第一个子模块后,我得到了类似的致命错误.

In other cases I was getting a fatal error similar to this after the clone of the first submodule.

fatal: git upload-pack: not our ref 89434ad65c1e697bfa311cd0260dfe1997985e65
fatal: remote error: upload-pack: not our ref 89434ad65c1e697bfa311cd0260dfe1997985e65
Fetched in submodule path 'soc', but it did not contain 89434ad65c1e697bfa311cd0260dfe1997985e65. Direct fetching of that commit failed.

我尝试将子模块直接添加到"m1",这似乎可以改善这种情况,但是我无法使用真正的存储库来做到这一点.

I tried adding submodules to 'm1' directly and it seemed to improve the situation, but I cannot do it with the real repos.

因此,所需的方案似乎不起作用.有办法解决吗?

So, the desired scheme does not seem to work. Is there a way to fix it?

推荐答案

git submodule add `realpath ../m1` m1
cd m1
git submodule add `realpath ../../m2` m2
git submodule add `realpath ../../m3` m3

在这里您修改了本地克隆的m1副本,但没有将更改推回原始m1.

Here you modified your locally cloned copy of m1 but you didn't push the change back to the original m1.

git commit -m 'added submodules'
cd ..
git commit -m 'added a submodule'

您忘记在子模块中添加更改.

You've forgotten to add changes in the submodule.

cd ..
git clone --recursive msub msub1

gitmsub克隆到msub1时,它将尝试从其原始目录而不是从msub/m1克隆m1.仅仅是因为在顶级.gitmodules中存在原始m1的路径.而且原始的m1没有子模块.

When git clones msub into msub1 it tries to clone m1 from its original directory, not from msub/m1. Simply because in the top-level .gitmodules there is the path to the original m1. And the original m1 doesn't have submodules.

要修复整个工作流程,您需要:

To fix the entire workflow you need:

  • git add在提交之前更改了m1
  • cd m1 && git push origin master(好吧,对于非裸仓库的push无效,因此对原始文档cdpull无效).
  • git add changed m1 before committing it;
  • cd m1 && git push origin master (well, push to a non-bare repo wouldn't work so cd to the original and pull instead).

因此整个固定脚本为:

#! /bin/sh
set -e

mkdir m1 ; cd m1 ; git init ; date > a.txt ; git add --all ; git commit -m added ; cd -
mkdir m2 ; cd m2 ; git init ; date > b.txt ; git add --all ; git commit -m added ; cd -
mkdir m3 ; cd m3 ; git init ; date > c.txt ; git add --all ; git commit -m added ; cd -
mkdir msub; cd msub; git init; date > d.txt; git add --all; git commit -m added;
git submodule add `realpath ../m1` m1
cd m1
git submodule add `realpath ../../m2` m2
git submodule add `realpath ../../m3` m3
git commit -m 'added submodules'
cd ../../m1
git pull ../msub/m1 master
cd ../msub
git add m1
git commit -m 'added a submodule'
cd ..
git clone --recursive msub msub1

这篇关于克隆带有嵌套子模块的存储库不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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