Github 如何下载仓库的部分文件
Update April 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 user interface.
- 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 Subversion (SVN). If you checkout your code with Subversion, GitHub will essentially convert the repository from Git to Subversion on the backend, and then serve up the requested directory.
Update November 2024: The Subversion support has been removed after January 8, 2024: https://github.blog/news-insights/product-news/sunsetting-subversion-support/. The rest of this answer is outdated and describes the functionality in the past.
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
- Pro tip: You can use
svn ls
to see available tags and branches before downloading if you wish
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)