简体   繁体   English

如何将git repo中的特定文件夹添加为git子模块?

[英]How can I add a specific folder from a git repo as a git submodule?

I have a git repo and I want to add a submodule to it. 我有一个git repo,我想为它添加一个子模块。 Problem is, the submodule exists as a folder inside another repo. 问题是,子模块作为另一个仓库内的文件夹存在。 Can I add only that folder as a submodule? 我可以只将该文件夹添加为子模块吗?

I ended up doing this: 我最终这样做了:

  1. Create a submodules directory. 创建submodules目录。
  2. Add the submodule in this directory. 在此目录中添加子模块。
  3. Create a symlink to the specific directory inside the submodule. 创建子模块内特定目录的符号链接。

This way you have default Git submodule behaviour and in your project you only use a subset of the whole submodule. 这样您就可以使用默认的Git子模块行为,并且在项目中只使用整个子模块的子集。

If you really need to include part of an other repository within the history of your own repo, then the subtree merge strategy is more adequate than submodules. 如果您确实需要在自己的repo的历史记录中包含其他存储库的一部分,那么子树合并策略比子模块更合适。

But in both case, the full repository is linked to your repo, not just one directory. 但在这两种情况下,完整存储库都链接到您的存储库,而不仅仅是一个目录。
And partial cloning is not possible . 部分克隆是不可能的

You could try and isolate that directory in its own repository, and then add it as a submodule, but that means its history will be totally seperated from the repo its was coming from originally. 您可以尝试在其自己的存储库中隔离该目录 ,然后将其添加为子模块,但这意味着它的历史将完全与它最初来自的repo分离。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM