如何从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导出目录,请将目录url中的“/tree/master/”替换为“trunk/”。
例如,要从以下URL导出目录:
https://github.com/liferay/liferay-plugins/tree/master/portlets/sample-hibernate-portlet
运行以下命令:
svn export https://github.com/liferay/liferay-plugins/trunk/portlets/sample-hibernate-portlet
其他回答
有一个名为githubdl的Python3pip包可以做到这一点*:
export GIT_TOKEN=1234567890123456789012345678901234567890123
pip install githubdl
githubdl -u http://github.com/foobar/test -d foo
项目页面在此处
*免责声明:这个包裹是我写的。
只需5步
从这里下载SVN。打开CMD并转到SVN bin目录,如:cd%ProgramFiles%\SlikSvn\bin假设我想下载这个目录URLhttps://github.com/ZeBobo5/Vlc.DotNet/tree/develop/src/Samples代替树/开发或树干的树/主现在启动最后一个命令以下载同一目录中的文件夹。
svn export https://github.com/ZeBobo5/Vlc.DotNet/trunk/src/Samples
试试看。
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存储库。(git初始化)启用稀疏检出。(git-config-core.sparsecheckout true)告诉Git你想要哪些目录(echo 2015/brand/May(参考你想要处理的文件夹)>>.Git/info/spease checkout)添加remote(gitremoteadd-f源https://jafartke.com/mkt-imdev/DVM.git)获取文件(git pull-origin master)