如何只从 git 子模块克隆一个文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3866733/
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 to clone only a folder from a git submodule?
提问by demula
I'm trying to get just a folder from an external github repo to use in my project.
我试图从外部 github 存储库中获取一个文件夹以在我的项目中使用。
I want my project setup to be like this:
我希望我的项目设置是这样的:
-my_project
-submodule
-code.py
-MY_README
-.git
And I have the remote repo named some-submodule with following structure:
我有名为 some-submodule 的远程仓库,其结构如下:
-submodule
-code.py
-README
-.gitignore
So I just want the submodule folder added to my project.
所以我只想将子模块文件夹添加到我的项目中。
But I end up with this after
但我最终得到了这个
git submodule add http://github.com/user/submodule.git submodule
-my_project
-submodule
-submodule
-code.py
-README
-.gitignore
-MY_README
-.gitignore
I am new to git so I really don't know if it possible using just git. If it is of some help I'm using msysgit on windows.
我是 git 的新手,所以我真的不知道是否可以只使用 git。如果有帮助,我将在 Windows 上使用 msysgit。
So, is there anyway that I can get a clean submodule folder in my project from a public repo?
那么,无论如何,我是否可以从公共存储库中获得我的项目中一个干净的子模块文件夹?
If you're curious of exactly what I'm trying to do I'm trying to take directly from their repos these django plugins 12to add them to my project.
如果您对我正在尝试做什么很好奇,我会尝试直接从他们的存储库中获取这些 django 插件1 2以将它们添加到我的项目中。
采纳答案by dregad
What you want to do is not feasible because you cannot clone a part of a repository.
您想要做的事情不可行,因为您无法克隆存储库的一部分。
See details in duplicate How to change a git submodule to point to a subfolder?
查看重复的详细信息如何更改 git 子模块以指向子文件夹?
回答by VonC
If you:
如果你:
git submodule add http://github.com/user/submodule.git
directly under my_project
, you should end up with the desired organization of directories.
直接在 下my_project
,您应该最终获得所需的目录组织。
From git submodule add
man page:
The optional argument
<path>
is the relative location for the cloned submodule to exist in the superproject.
If<path>
is not given, the "humanish" part of the source repository is used ("repo" for "/path/to/repo.git
" and "foo
" for "host.xz:foo/.git
").
可选参数
<path>
是克隆子模块在超级项目中存在的相对位置。
如果<path>
未给出,则使用源存储库的“人性化”部分(“repo”代表“/path/to/repo.git
”,“foo
”代表“host.xz:foo/.git
”)。
回答by Immanuel
just
只是
git submodule update --init --recursive
in the root-directory of your project and it should do what you want
在你的项目的根目录中,它应该做你想做的