我可以使用 git 子模块命令导入另一个存储库的子集吗?
Can I use the git submodule command to import a subset of another repository?
我正在做一个需要导入一些开源库的Godot项目。这些库都共享一个特定的文件夹结构,这意味着我无法直接使用 git submodule add
.
导入项目
这是一个这样的图书馆。我创建了自己的 official repo 分支,并在导入前对其进行了修改。官方回购看起来像这样。我想从此库中导入 quentincaffeino-console
文件夹并将其添加到我项目的 addons
文件夹中。 (我不想直接将文件签入我的存储库,我宁愿将它们分开。)
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
我的解决方案是创建 my own fork,删除所有单元测试和基础结构文件,并将插件文件夹的内容移动到存储库的根目录:
quentincaffeino-console
└───src
现在我可以将库作为子存储库添加到 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 submodule
或类似命令将我想要的文件夹拉到我的项目中?
额外的细节:
我发现了一些类似的问题 here and here。我不是我要导入的库的 owner/maintainer,所以我不能直接修改该项目的结构。
此外,这是一个在 CICD 管道中运行的开源项目,所以我想让客户端易于理解。现在,我可以使用 git clone
和 git submodule --init
克隆我的项目。我会接受“git 不能那样做”作为答案,我只想听听专家的意见:-)
编辑:我刚刚发现 10 年前的 this answer 说“不,这是不可能的”,但最近的答案似乎表明并非如此。今天仍然如此吗? (抱歉,如果重复)
谢谢!
Is this still true today?
是的,今天仍然如此:一个子模块引用了一个完整的存储库。
你可以, in order to display only a subset of its content (see also this example).
但在你的情况下,你仍然需要一个 symlink(符号 link)以使 quentincaffeino-console
在你的主存储库中你想要的地方可见。
我正在做一个需要导入一些开源库的Godot项目。这些库都共享一个特定的文件夹结构,这意味着我无法直接使用 git submodule add
.
这是一个这样的图书馆。我创建了自己的 official repo 分支,并在导入前对其进行了修改。官方回购看起来像这样。我想从此库中导入 quentincaffeino-console
文件夹并将其添加到我项目的 addons
文件夹中。 (我不想直接将文件签入我的存储库,我宁愿将它们分开。)
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
我的解决方案是创建 my own fork,删除所有单元测试和基础结构文件,并将插件文件夹的内容移动到存储库的根目录:
quentincaffeino-console
└───src
现在我可以将库作为子存储库添加到 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 submodule
或类似命令将我想要的文件夹拉到我的项目中?
额外的细节:
我发现了一些类似的问题
此外,这是一个在 CICD 管道中运行的开源项目,所以我想让客户端易于理解。现在,我可以使用 git clone
和 git submodule --init
克隆我的项目。我会接受“git 不能那样做”作为答案,我只想听听专家的意见:-)
编辑:我刚刚发现 10 年前的 this answer 说“不,这是不可能的”,但最近的答案似乎表明并非如此。今天仍然如此吗? (抱歉,如果重复)
谢谢!
Is this still true today?
是的,今天仍然如此:一个子模块引用了一个完整的存储库。
你可以
但在你的情况下,你仍然需要一个 symlink(符号 link)以使 quentincaffeino-console
在你的主存储库中你想要的地方可见。