如何从GitHub上托管的远程Git repo中仅下载特定文件夹或目录?

举个GitHub repo的例子:

git@github.com:foobar/Test.git

其目录结构:

Test/
├── foo/ 
│   ├── a.py
│   └── b.py   
└── bar/
    ├── c.py
    └── d.py

我只想下载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"

其他回答

只需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

如果在特殊情况下需要存储库中的某个文件,则会出现此问题。

这里可以找到一个简短的答案。您应该将url更改为以下格式:

https://raw.github.com/user/repository/branch/file.name

简单地解释一下,从github输入您想要的url。生吃。在url地址中的github之前,并从地址中删除blob。例如,假设您想要获取此地址中的csv文件:

https://github.com/CSSEGISandData/COVID-19/blob/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv

您应该将url更改为以下url:

https://raw.github.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv

对于通用git Repo:

如果您想下载文件,而不是克隆具有历史记录的存储库,可以使用gitarchive来完成此操作。

gitarchive生成git存储库的压缩zip或tar存档。让它与众不同的一些东西:

您可以选择git存储库中要归档的文件或目录。它不会将.git/文件夹或其运行的存储库中任何未跟踪的文件归档。您可以归档特定的分支、标记或提交。使用git管理的项目通常使用它来生成项目版本(beta、release、2.0等)的存档,供用户下载。

使用ssh从远程存储库创建docs/usage目录归档的示例:

# in terminal
$ git archive --format tar --remote ssh://server.org/path/to/git HEAD docs/usage > /tmp/usage_docs.tar

更多信息请参阅本博客文章和git文档。

GitHub Repos注意事项:

GitHub不允许git存档访问。☹️

如果您需要以编程方式执行,并且不想依赖SVN,则可以使用GitHubAPI递归下载所有内容。

为了获得灵感,以下是我的红宝石要点:https://gist.github.com/cvengros/b2a7e82f66519d423b6f

一个简单的答案是从下面的链接中选择第一个乌龟svn。

https://tortoisesvn.net/downloads.html

安装时打开CLI选项,以便可以从命令行界面使用它。

复制github子目录链接。

实例https://github.com/tensorflow/models/tree/master/research/deeplab

用树干替换树/主

https://github.com/tensorflow/models/trunk/research/deeplab

并且做到了

svn检出https://github.com/tensorflow/models/trunk/research/deeplab

文件将被下载到当前目录中的deeplab文件夹中。