如何使用子模块克隆本地存储库? [英] How do I clone a local repo with submodules?

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

问题描述

说我递归地克隆一个仓库.

Say I recursively clone a repo.

$ git clone --recursive ssh://server/project/client
Cloning into 'client'...
remote: Counting objects: 191, done
remote: Finding sources: 100% (191/191)
remote: Total 191 (delta 53), reused 159 (delta 53)
Receiving objects: 100% (191/191), 27.59 KiB | 0 bytes/s, done.
Resolving deltas: 100% (53/53), done.
Checking connectivity... done.
Submodule 'gui' (ssh://server/project/client/gui.git) registered for path 'gui'
Cloning into 'gui'...
remote: Counting objects: 3213, done
remote: Finding sources: 100% (3213/3213)
remote: Total 3213 (delta 1272), reused 3107 (delta 1272)
Receiving objects: 100% (3213/3213), 47.88 MiB | 12.05 MiB/s, done.
Resolving deltas: 100% (1272/1272), done.
Checking connectivity... done.
Submodule path 'gui': checked out '7315db8d7a8b36929f7874dc5477359839ec51ce'

现在,我想创建该本地存储库的本地克隆(也许在本地进行更改并提交更改之后).

Now I want to create a local clone of that local repo (perhaps after making and committing changes locally).

$ git clone --recursive client/ client_copy
Cloning into 'client_copy'...
done.
Submodule 'gui' (/home/deployer/client/gui.git) registered for path 'gui'
fatal: repository '/home/deployer/client/gui.git' does not exist
Clone of '/home/deployer/client/gui.git' into submodule path 'gui' failed

我的.gitmodules文件如下所示:

[submodule "gui"]
        path = gui
        url = ../client/gui.git

这为什么会失败,我该如何解决这个问题?

Why does this fail, and how can I address the issue?

推荐答案

问题出在您的.gitmodules文件中.项目中的子模块url定义为超级项目存储库中的相对路径,但是当克隆子模块时,将使用path位置放置子模块.

The issue is with your .gitmodules file. The submodule url in your project is defined as a relative path from the superproject repository, but when the submodules are cloned, they are placed using the path location.

换句话说,git试图从url位置拉出子模块,但是在您的本地计算机上,它们实际上是在path位置.

In other words, git is trying to pull the submodules from the url location, but on your local machine, they're actually at the path location.

要解决此问题,请仅克隆本地超级项目存储库(git clone /path/to/superproject),然后进入新克隆的.gitsubmodules并将url更改为./<whatever-the-path-is>.例如,您的gui子模块将变为:

To fix this, clone just the local superproject repository (git clone /path/to/superproject), then go into the new clone's .gitsubmodules and change the urls to be ./<whatever-the-path-is>. For example, your gui submodule would become:

[submodule "gui"]
        path = gui
        url = ./gui

.gitmodules中的每个子模块更改为这样,然后运行:

Change each submodule in .gitmodules to be like this, then run:

git submodule sync
git submodule update --init --recursive

那应该做到!

这篇关于如何使用子模块克隆本地存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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