我可以使用git submodule命令导入另一个存储库的子集吗? [英] Can I use the git submodule command to import a subset of another repository?
问题描述
我正在研究Godot项目,该项目需要导入一些开源库.这些库都共享一个特定的文件夹结构,这意味着我不能直接使用 git子模块add
导入项目.
I am working on a Godot project that needs to import some open-source libraries. These libraries all share a particular folder structure which means that I can't directly import the projects with git submodule add
.
这是一个这样的图书馆.我创建了自己的官方仓库的分支,并在导入之前对其进行了修改.官方仓库看起来像这样.我想从该库中导入 quentincaffeino-console
文件夹,并将其添加到我项目的 addons
文件夹中.(我不想直接将文件检入到存储库中,而是希望将它们分开存放.)
Here is one such library. I created my own fork of the official repo and modified it before importing. The official repo looks something like this. I want to import the quentincaffeino-console
folder from this library and add it to my project's addons
folder. (I don't want to check the files into my repository directly, I would rather keep them separate.)
godot-console
├───assets*
├───gdscript-docs-maker*
└───godot*
├───addons
│ └───quentincaffeino-console -- I want to import this folder only
│ └───src -- (and subfolders, of course)
├───assets*
├───demo*
└───etc...
* These folders contain unit tests, docs, etc. but should NOT be a part of my project
我的解决方案是创建我自己的叉子,删除所有单元测试和基础结构文件,并将addons文件夹的内容移动到存储库的根目录:
My solution was to create my own fork, delete all unit test and infrastructure files, and move the contents of the addons folder to the root of the repository:
quentincaffeino-console
└───src
现在,我可以将库作为子仓库添加到我的项目:
Now I can add the library as a subrepo to my project:
Demo
├───addons
│ ├───quentincaffeino-console -- Created with "git submodule add https://github.com/SdgGames/godot-console"
│ │ └───src
│ ├───gut -- Another submodule created the same way
│ ├───logger -- Another
│ └───sdggames-modloader -- etc...
└───etc.
这有效,但是似乎有些混乱,因为我现在必须保持多个存储库分支与其上游副本保持最新.有没有一种方法可以跳过中间步骤,并使用 git子模块
或类似命令将我想要的文件夹拖入我的项目中?
This works, but it seems a bit messy as I now have to keep multiple repository forks up to date with their upstream counterparts. Is there a way to skip the middle step and pull the folder I want into my project using a git submodule
or similar command?
其他详细信息:
I found some similar questions here here and here. I am NOT the owner/maintainer of the library I want to import, so I can't modify that project's structure directly.
此外,这是一个在CICD管道中运行的开源项目,因此我希望使客户端易于理解.现在,我可以使用 git clone
和 git子模块--init
克隆我的项目.我会接受"git无法做到"作为回答,我只想听听专家的意见:-)
Also, this is an open source project that runs in a CICD pipeline, so I want to keep the client side easy to understand. Right now, I can clone my project with git clone
and git submodule --init
. I will accept "git can't do that" as an answer, I just want to hear it from an expert :-)
我刚刚找到10年前的此答案,上面写着不,这是不可能的".但是最近的答案似乎表明情况并非如此.今天仍然如此吗?(很抱歉,如果重复的话)
I just found this answer from 10 years ago that says "no, it's not possible," but more recent answers seem to indicate otherwise. Is this still true today? (Sorry if it's a duplicate)
谢谢!
推荐答案
今天仍然如此吗?
Is this still true today?
是的,今天仍然适用:子模块引用了完整的存储库.
Yes, still true today: a submodule reference a full repository.
您可以配置要稀疏检出的子模块,以便仅显示其内容的子集(另请参见此示例).
You can configure a submodule to be sparse-checked out, in order to display only a subset of its content (see also this example).
但是,在您的情况下,您仍然需要一个符号链接(符号链接),以使 quentincaffeino-console
在您的主存储库中的所需位置可见.
But in your case, you would still need a symlink (symbolic link) in order to make quentincaffeino-console
visible where you want it in your main repository.
这篇关于我可以使用git submodule命令导入另一个存储库的子集吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!