git 如何从github下载文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33066582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:38:02  来源:igfitidea点击:

How to download a folder from github?

gitgithububuntu-14.04

提问by Gangesh

I wished to download the mysite folder from this link: https://github.com/username/repository/master/

我想从这个链接下载 mysite 文件夹:https: //github.com/username/repository/master/

采纳答案by C1sc0

There is a button Download ZIP. If you want to do a sparse checkout there are many solutions on the site. For example here.

有一个按钮Download ZIP。如果您想进行稀疏结账,网站上有很多解决方案。例如这里。

回答by Anona112

You candownload a file/folder from github

可以从 github 下载文件/文件夹

simply use

简单地使用

svn export <repo>/trunk/<folder>

svn export <repo>/trunk/<folder>

e.g.

例如

svn export https://github.com/lodash/lodash/trunk/docs

svn export https://github.com/lodash/lodash/trunk/docs

(yes, that's svn here. apparently in 2016 you still need svn to simply download some github files)

(是的,这里是 svn。显然在 2016 年你仍然需要 svn 来简单地下载一些 github 文件)

回答by chuyik

You can use Github Contents APIto get an archive link and tarto retrieve a specified folder.

您可以使用Github Contents API获取存档链接并tar检索指定的文件夹。

Command line:

命令行:

curl https://codeload.github.com/[owner]/[repo]/tar.gz/master | \ tar -xz --strip=2 [repo]-master/[folder_path]

curl https://codeload.github.com/ [owner]/ [repo]/tar.gz/master | \ tar -xz --strip=2 [repo]-master/ [folder_path]



For example,
if you want to download examples/with-apollo/folder from zeit/next.js, you can type this:

例如,
如果你想从zeit/next.js下载examples/with-apollo/文件夹,你可以输入:

curl https://codeload.github.com/zeit/next.js/tar.gz/master | \
  tar -xz --strip=2 next.js-master/examples/with-apollo

回答by gdrt

Use GitZip online tool. It allows to download a sub-directory of a github repository as a zip file. No git commands needed!

使用GitZip 在线工具。它允许将 github 存储库的子目录下载为 zip 文件。不需要 git 命令!

回答by Kalpesh Kundanani

Dependency: cURLand 7-Zip.

依赖:cURL7-Zip

curl {url for downloading zip file} | 7z a -tzip {project name}-{branch name}/{folder path in that branch}

for example:

例如:

curl https://github.com/hnvn/flutter_shimmer/archive/master.zip | 7z a -tzip flutter_shimmer-master/examples

回答by abu_bua

How to download a specific folder from a GitHub repo

如何从 GitHub 存储库下载特定文件夹

Here a proper solution according to this post:

根据这篇文章,这里有一个适当的解决方案:

  • Create a directory

    mkdir github-project-name 
    cd github-project-name
    
  • Set up a git repo

    git init
    git remote add origin -f <URL-link of the repo>
    
  • Configure your git-repo to download only specific directories

    git config core.sparseCheckout true # enable this
    
  • Set the folder you like to be downloaded, e.g. you only want to download the doc directory from https://github.com/project-tree/master/doc

    echo "/absolute/path/to/folder" > .git/info/sparse-checkout 
    

    E.g. if you only want to download the doc directory from your master repo https://github.com/project-tree/master/doc, then your command is echo "doc" > .git/info/sparse-checkout.

  • Download your repo as usual

    git pull origin master
    
  • 创建目录

    mkdir github-project-name 
    cd github-project-name
    
  • 设置一个 git 仓库

    git init
    git remote add origin -f <URL-link of the repo>
    
  • 配置您的 git-repo 以仅下载特定目录

    git config core.sparseCheckout true # enable this
    
  • 设置你喜欢下载的文件夹,例如你只想下载doc目录 https://github.com/project-tree/master/doc

    echo "/absolute/path/to/folder" > .git/info/sparse-checkout 
    

    例如,如果您只想从主存储库下载 doc 目录 https://github.com/project-tree/master/doc,那么您的命令是echo "doc" > .git/info/sparse-checkout.

  • 像往常一样下载你的仓库

    git pull origin master
    

回答by Paran0a

You have to download the whole project with either "Clone to desktop" button that will use native github program or "Download as zip".

您必须使用“克隆到桌面”按钮下载整个项目,该按钮将使用本机 github 程序或“下载为 zip”。

And then search that folder in downloaded project.

然后在下载的项目中搜索该文件夹。

回答by VIKAS KOHLI

You can download the complete folder under Clone or Download options (Git URL or Download Zip)

您可以在克隆或下载选项(Git URL 或下载 Zip)下下载完整文件夹

  1. There is a button of Download Zip

  2. By using command you can download the complete folder on your machine but for that you need git on your machine. You can find the Git url uner

    git clone https://github.com/url

  1. 有一个下载 Zip 的按钮

  2. 通过使用命令,您可以在您的机器上下载完整的文件夹,但为此您需要在您的机器上安装 git。你可以在下面找到 Git url

    git 克隆 https://github.com/url

回答by user2963512

You can also just clone the repo, after cloning is done, just pick the folder or vile that you want. To clone:

您也可以只克隆 repo,克隆完成后,只需选择您想要的文件夹或 vile。克隆:

git clone https://github.com/somegithubuser/somgithubrepo.git

then go to the cloned DIR and find your file or DIR you want to copy.

然后转到克隆的 DIR 并找到要复制的文件或 DIR。