如何从GitHub上托管的远程Git repo中仅下载特定文件夹或目录?
举个GitHub repo的例子:
git@github.com:foobar/Test.git
其目录结构:
Test/
├── foo/
│ ├── a.py
│ └── b.py
└── bar/
├── c.py
└── d.py
我只想下载foo文件夹,而不是克隆整个测试项目。
如何从GitHub上托管的远程Git repo中仅下载特定文件夹或目录?
举个GitHub repo的例子:
git@github.com:foobar/Test.git
其目录结构:
Test/
├── foo/
│ ├── a.py
│ └── b.py
└── bar/
├── c.py
└── d.py
我只想下载foo文件夹,而不是克隆整个测试项目。
当前回答
其他答案没有错,但我只是想为那些第一次在这个过程中徘徊的人分享一步一步的指导。
如何从github存储库(Mac OS X)下载单个文件夹:
~要打开终端,只需单击聚光灯并键入终端,然后点击enter
在Mac上,您可能已经拥有SVN(只需测试开放终端和键入“svn”或“which svn”~(不带引号)在Github上:通过单击repo中的特定文件夹名称,找到git文件夹(而不是repo)的Github路径从浏览器的地址栏复制路径打开终端并键入:svn export下一步粘贴地址(例如):https://github.com/mingsai/Sample-Code/tree/master/HeadsUpUI替换单词:tree/master带有单词:trunk键入文件的目标文件夹(在本例中,I将目标文件夹存储在当前用户)这里空格只是空格键而不是单词(空格)~/Downloads/HeadsUpUI最后一个终端命令显示下载文件夹(将地址与步骤5进行比较)svn导出https://github.com/mingsai/Sample-Code/trunk/HeadsUpUI~/下载/HeadsUpUI
BTW-如果您在Windows或其他平台上,您可以在以下位置找到subversion(svn)的二进制下载http://subversion.apache.org
~如果您想签出文件夹而不是简单地下载它,请尝试使用svn帮助(tldr:replace export with checkout)
使现代化
关于恢复中断的下载/签出的评论。我会尝试先运行svn清理,然后再运行svn更新。请在SO中搜索其他选项。
其他回答
有一个名为githubdl的Python3pip包可以做到这一点*:
export GIT_TOKEN=1234567890123456789012345678901234567890123
pip install githubdl
githubdl -u http://github.com/foobar/test -d foo
项目页面在此处
*免责声明:这个包裹是我写的。
试试看。
https://github.com/twfb/git-directory-download
usage: gitd [-h] [-u URL] [-r] [-p] [--proxy PROXY]
optional arguments:
-h, --help show this help message and exit
-u URL, --url URL github url, split by ",", example: "https://x, http://y"
-r, --raw download from raw url
-p, --parse download by parsing html
--proxy PROXY proxy config, example "socks5://127.0.0.1:7891"
Example:
1. download by raw url: gitd -u "https://github.com/twfb/git-directory-download"
2. download by raw url: gitd -r -u "https://github.com/twfb/git-directory-download"
3. dowmload by parsing: gitd -p -u "https://github.com/twfb/git-directory-download"
4. download by raw url with proxy: gitd -r -u "https://github.com/twfb/git-directory-download" --proxy "socks5://127.0.0.1:7891"
可以按以下方式使用git-svn。
首先,用主干替换树/主节点然后,通过sudoaptinstallgitsvn安装gitsvn
git svn clone https://github.com/lodash/lodash/trunk/test
这样,您就不必经历设置svn的痛苦,特别是针对Windows用户。
我找到的最简单的方法是如何仅克隆Git存储库的子目录?
我在gitclone命令中添加了-b<branch>--singlebranch以下载特定的分支。所以我使用的命令是:
git clone --depth 1 --single-branch -b <branch> --filter=blob:none --sparse <url>
git sparse-checkout set <directory>
我们的团队为此编写了一个bash脚本,因为我们不想在我们的裸机服务器上安装SVN。
https://github.com/ojbc/docker/blob/master/java8-karaf3/files/git-download.sh
它使用github API,可以从如下命令行运行:
git-download.sh https://api.github.com/repos/ojbc/main/contents/shared/ojb-certs