如何初始化嵌套在子树中的子模块? [英] How do I init submodules nested in a subtree?

查看:63
本文介绍了如何初始化嵌套在子树中的子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,添加具有子模块的存储库的子树将破坏git submodule init.这是一个重现该问题的脚本:

Apparently, adding a subtree of a repository that has submodules will break git submodule init. Here is a script which reproduces the problem:

#!/bin/sh
set -ex

mkdir submod
cd submod
git init
touch foo
git add foo
git commit -asm "This is a submodule"
cd ..

mkdir subtree
cd subtree
git init
git submodule add `realpath ../submod` submod
git commit -asm "This has reference to submodule"
cd ..

mkdir top
cd top
git init
touch bar
git add bar
git commit -asm "Dummy commit so HEAD resolves correctly"
git subtree add --prefix=subtree `realpath ../subtree` master

# This fails!
git submodule init

此脚本正在执行的操作是:

What this script is doing is:

  1. 创建一个repo子模块
  2. 创建一个repo子树,该子树具有对submod的子模块引用
  3. 创建一个具有子树引用子树的仓库顶部

进一步考虑后,很清楚问题出在哪里:子树机制已将子树的子模块引用添加到树的submod中,但是.gitmodules元数据保留在subtree/.gitmodules中,而不是顶级.gitmodules中,这意味着git submodule init失败.如果我们将subtree/.gitmodules的内容复制到.gitmodules,相应地调整所有路径,就可以解决问题...

Upon further consideration, it is clear what the problem is: the subtree mechanism has added subtree's submodule reference to submod to the tree, but the .gitmodules metadata remains in subtree/.gitmodules, not the top-level .gitmodules, which means that git submodule init fails. If we copy the contents of subtree/.gitmodules to .gitmodules, adjusting all the paths accordingly, that solves the problem...

[submodule "submod"]
    path = subtree/submod
    url = /Users/ezyang/Dev/labs/git-subtree-submod/submod

...但是,如果子树有很多子模块,那会有些痛苦.有更好的方法吗?

...but it is a bit of pain if the subtree has a lot of submodules. Is there a better way to do this?

推荐答案

据我所知,阅读文档和源代码... Git子树与Git子模块完全独立,并且不会有效管理子树项目本身中可能包含的任何子模块.

From what I can tell reading the docs and source code... Git subtree is completely separate from Git submodules and will not actively manage any submodules that may be contained within the subtree project itself.

您发现,对git submodule init的功能至关重要的.gitsubmodules,需要保留在主"存储库的根目录中(因为缺少更好的术语).

As you found out, .gitsubmodules, which is critical to the function of git submodule init, needs to be maintained in the root of the "main" repository (for lack of a better term).

进一步考虑后,很明显问题出在哪里: 子树机制已将子树的子模块引用添加到submod,以 树,但是.gitmodules元数据保留在subtree/.gitmodules中, 不是顶级.gitmodules,这意味着git子模块是init 失败.如果我们将subtree/.gitmodules的内容复制到.gitmodules, 相应地调整所有路径,即可解决问题...

Upon further consideration, it is clear what the problem is: the subtree mechanism has added subtree's submodule reference to submod to the tree, but the .gitmodules metadata remains in subtree/.gitmodules, not the top-level .gitmodules, which means that git submodule init fails. If we copy the contents of subtree/.gitmodules to .gitmodules, adjusting all the paths accordingly, that solves the problem...

我强烈建议不要混合使用这些功能.

I strongly recommend not mixing these features.

这篇关于如何初始化嵌套在子树中的子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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