如何将 git repo 中的特定文件夹添加为 git 子模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3158597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I add a specific folder from a git repo as a git submodule?
提问by tuxcanfly
I have a git repo and I want to add a submodule to it. Problem is, the submodule exists as a folder inside another repo. Can I add only that folder as a submodule?
我有一个 git repo,我想向其中添加一个子模块。问题是,子模块作为另一个存储库中的文件夹存在。我可以只添加该文件夹作为子模块吗?
采纳答案by VonC
If you really need to include part of an other repository within the history of your own repo, then the subtree merge strategyis more adequate than submodules.
如果你真的需要在你自己的仓库历史中包含其他仓库的一部分,那么子树合并策略比子模块更合适。
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 directoryin 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.
您可以尝试在其自己的存储库中隔离该目录,然后将其添加为子模块,但这意味着其历史记录将与最初来自的存储库完全分离。
回答by gitaarik
I ended up doing this:
我最终这样做了:
- Create a
submodules
directory. - Add the submodule in this directory.
- Create a symlink to the specific directory inside the submodule.
- 创建一个
submodules
目录。 - 在此目录中添加子模块。
- 创建指向子模块内特定目录的符号链接。
This way you have default Git submodule behaviour and in your project you only use a subset of the whole submodule.
这样你就有默认的 Git 子模块行为,并且在你的项目中你只使用整个子模块的一个子集。
回答by BinaryMaker
- Create new branch
- Move required files to new branch
- Add sub module to super repository
- Checkout sub-module to new branch
- 创建新分支
- 将所需文件移动到新分支
- 将子模块添加到超级存储库
- 将子模块结帐到新分支