从GitHub仓库下载单个文件夹或目录 [英] Download a single folder or directory from a GitHub repo
问题描述
如何从GitHub上托管的远程Git仓库中只下载特定的文件夹或目录?
b$ b
git@github.com:foobar / Test.git
其目录结构:
测试/
foo /
a .py
b.py
bar /
c.py
d.py
我只想下载 foo 文件夹,而不是克隆整个Test项目。
-
-
修改Subversion的URL 。我想从
master
分支中下载/ docs
文件夹,所以我将追加躯干/文档
。完整网址现在https://github.com/lodash/lodash/trunk/docs
。请参阅下面的注释,以获取有关我们为什么必须使用此URL格式的更深入解释。 下载文件夹。转到命令行并用SVN抓取文件夹。
svn checkout https://github.com/lodash/lodash/trunk/docs
- '对
master
分支感兴趣,请改为使用trunk
。所以完整路径是trunk / foldername
- 如果您对
foo $ c $感兴趣c>分支,改为使用
branches / foo
。
完整路径看起来像branches / foo / foldername
- Protip:您可以使用
svn
您可能无法立即看到任何活动,因为Github需要长达30秒才能转换较大的存储库,因此请耐心等待。
完整的网址格式说明:
可在下载前查看可用的标签和分支。就这样! Github 还支持更多的颠覆功能,包括对提交和推送的支持更改。
How can I download only a specific folder or directory from a remote Git repo hosted on GitHub?
Say the example GitHub repo lives here:
git@github.com:foobar/Test.git
Its directory structure:
Test/
foo/
a.py
b.py
bar/
c.py
d.py
I want to download only the foo folder and not clone the whole Test project.
Update Sep. 2016: there are a few tools created by the community that can do this for you:
GitZip (Credits to Kino - upvote his answer right here!)
DownGit (Credits to Minhas Kamal - upvote his answer right here!)
Git doesn't support this, but Github does via SVN. If you checkout your code with subversion, Github will essentially convert the repo from git to subversion on the backend, then serve up the requested directory.
Here's how you can use this feature to download a specific folder. I'll use the popular javascript library lodash
as an example.
Get the repo URL. First, copy the URL of the Github repo to your clipboard.
Modify the URL for subversion. I want to download the folder at
/docs
from themaster
branch, so I will appendtrunk/docs
. Full URL is nowhttps://github.com/lodash/lodash/trunk/docs
. See my note below for a more in-depth explanation of why we must use this URL format.Download the folder. Go to the command line and grab the folder with SVN.
svn checkout https://github.com/lodash/lodash/trunk/docs
You might not see any activity immediately because Github takes up to 30 seconds to convert larger repositories, so be patient.
Full URL format explanation:
- If you're interested in
master
branch, usetrunk
instead. So the full path istrunk/foldername
- If you're interested in
foo
branch, usebranches/foo
instead. The full path looks likebranches/foo/foldername
- Protip: You can use
svn ls
to see available tags and branches before downloading if you wish
That's all! Github supports more subversion features as well, including support for committing and pushing changes.
这篇关于从GitHub仓库下载单个文件夹或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!