从GitHub仓库下载单个文件夹或目录 [英] Download a single folder or directory from a GitHub repo

查看:769
本文介绍了从GitHub仓库下载单个文件夹或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

b
$ b

  git@github.com:foobar / Test.git 

其目录结构:

 测试/ 
foo /
a .py
b.py
bar /
c.py
d.py

我只想下载 foo 文件夹,而不是克隆整个Test项目。

解决方案< 2016年9月更新:社区可以创建一些工具,可以为您做到这一点:





  • 修改Subversion的URL 。我想从 master 分支中下载 / docs 文件夹,所以我将追加躯干/文档。完整网址现在 https://github.com/lodash/lodash/trunk/docs 。请参阅下面的注释,以获取有关我们为什么必须使用此URL格式的更深入解释。 下载文件夹。转到命令行并用SVN抓取文件夹。

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


  • 您可能无法立即看到任何活动,因为Github需要长达30秒才能转换较大的存储库,因此请耐心等待。


    完整的网址格式说明:


    • '对 master 分支感兴趣,请改为使用 trunk 。所以完整路径是 trunk / foldername

    • 如果您对 foo 分支,改为使用 branches / foo
      完整路径看起来像 branches / foo / foldername

    • Protip:您可以使用 svn




    可在下载前查看可用的标签和分支。就这样! Github 还支持更多的颠覆功能,包括对提交和推送的支持更改。


    How can I download only a specific folder or directory from a remote Git repo hosted on GitHub?

    Say the example GitHub repo lives here:

    git@github.com:foobar/Test.git
    

    Its directory structure:

    Test/
        foo/ 
           a.py
           b.py
        bar/
           c.py
           d.py
    

    I want to download only the foo folder and not clone the whole Test project.

    解决方案

    Update Sep. 2016: there are a few tools created by the community that can do this for you:


    Git doesn't support this, but Github does via SVN. If you checkout your code with subversion, Github will essentially convert the repo from git to subversion on the backend, then serve up the requested directory.

    Here's how you can use this feature to download a specific folder. I'll use the popular javascript library lodash as an example.

    1. Get the repo URL. First, copy the URL of the Github repo to your clipboard.

    2. Modify the URL for subversion. I want to download the folder at /docs from the master branch, so I will append trunk/docs. Full URL is now https://github.com/lodash/lodash/trunk/docs. See my note below for a more in-depth explanation of why we must use this URL format.

    3. Download the folder. Go to the command line and grab the folder with SVN. svn checkout https://github.com/lodash/lodash/trunk/docs

    You might not see any activity immediately because Github takes up to 30 seconds to convert larger repositories, so be patient.

    Full URL format explanation:

    • If you're interested in master branch, use trunk instead. So the full path is trunk/foldername
    • If you're interested in foo branch, use branches/foo instead. The full path looks like branches/foo/foldername
    • Protip: You can use svn ls to see available tags and branches before downloading if you wish

    That's all! Github supports more subversion features as well, including support for committing and pushing changes.

    这篇关于从GitHub仓库下载单个文件夹或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆