如何从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文件夹,而不是克隆整个测试项目。
当前回答
你可以尝试为chrome使用gitzip扩展,它超级容易使用,而且以前也帮我下载了很多文件夹!
其他回答
只需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
要从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
我找到的最简单的方法是如何仅克隆Git存储库的子目录?
我在gitclone命令中添加了-b<branch>--singlebranch以下载特定的分支。所以我使用的命令是:
git clone --depth 1 --single-branch -b <branch> --filter=blob:none --sparse <url>
git sparse-checkout set <directory>
为了放大上面的答案,一个从真正的GitHub存储库到本地目录的真实示例是:
svn ls https://github.com/rdcarp/playing-cards/trunk/PumpkinSoup.PlayingCards.Interfaces
svn export https://github.com/rdcarp/playing-cards/trunk/PumpkinSoup.PlayingCards.Interfaces /temp/SvnExport/Washburn
有时,一个具体的例子有助于澄清所提出的替代方案。
如果您需要以编程方式执行,并且不想依赖SVN,则可以使用GitHubAPI递归下载所有内容。
为了获得灵感,以下是我的红宝石要点:https://gist.github.com/cvengros/b2a7e82f66519d423b6f