从 GitHub 存储库下载单个文件夹或目录 [英] Download a single folder or directory from a GitHub repo
问题描述
如何仅从托管在 GitHub 上的远程 Git 存储库下载特定文件夹或目录?
假设示例 GitHub 存储库位于此处:
git@github.com:foobar/Test.git
其目录结构:
测试/├── foo/│ ├── a.py│ └── b.py└── 酒吧/├── c.py└── d.py
我只想下载 foo 文件夹而不是克隆整个测试项目.
2021 年 4 月更新:社区创建的一些工具可以为您执行此操作:
修改 subversion 的 URL.将
tree/master
替换为trunk
.https://github.com/lodash/lodash/tree/master/test
➜https://github.com/lodash/lodash/trunk/test
下载文件夹.转到命令行并使用 SVN 抓取文件夹.
svn checkout https://github.com/lodash/lodash/trunk/test
您可能不会立即看到任何活动,因为 Github 最多需要 30 秒来转换更大的存储库,所以请耐心等待.
<块引用>完整的 URL 格式说明:
- 如果您对
master
分支感兴趣,请改用trunk
.所以完整路径是trunk/foldername
- 如果您对
foo
分支感兴趣,请改用branches/foo
.这完整路径看起来像branches/foo/foldername
- 提示:如果您愿意,您可以在下载前使用
svn ls
查看可用的标签和分支
仅此而已!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 Apr. 2021: there are a few tools created by the community that can do this for you:
- Download Directory (Credits to fregante)
- It has also been integrated into the excellent Refined Github chrome extension as a button in the Github web UI.
- GitZip (Credits to Kino - see his answer here)
- DownGit (Credits to Minhas Kamal - see his answer here)
Note: if you're trying to download a large number of files, you may need to provide a token to these tools to avoid rate limiting.
Original (manual) approach: Checking out an individual directory is not supported by git
natively, but Github can do this 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.
Navigate to the folder you want to download. Let's download
/test
frommaster
branch.Modify the URL for subversion. Replace
tree/master
withtrunk
.https://github.com/lodash/lodash/tree/master/test
➜https://github.com/lodash/lodash/trunk/test
Download the folder. Go to the command line and grab the folder with SVN.
svn checkout https://github.com/lodash/lodash/trunk/test
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屋!