从GitHub下载单个文件 [英] Download single files from GitHub

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

问题描述

我想大多数人,开发人员都使用任何 VCS ,我希望你们中的一些人使用Git。你有任何提示或诀窍如何获取存储库中单个文件的下载URL?



我不希望URL显示原始文件;在二进制文件的情况下它是没有用的。



http://support.github.com/discussions/feature-requests/41-download-single-file



是否有可能使用GitHub作为下载服务器?



如果我们决定切换到Google Code,这里提到的功能是什么?



或者是否有任何免费的托管和VCS用于开源项目?

解决方案

Git不支持下载部分版本库。你必须全部下载。但你应该可以用GitHub来做到这一点。



当你查看一个文件时,它有一个指向原始版本的链接。 URL 的构造方式如此

  https://github.com/user/repository/raw/branch/filename 

通过填充网址中的空白,您可以使用 Wget cURL (使用 -L 选项,见下文)或任何下载单个文件。同样,你也不会得到Git使用的任何漂亮的版本控制功能。

更新:我注意到你提到这对二进制文件不起作用。您可能不应该在您的Git存储库中使用二进制文件,但GitHub为每个可用于上载文件的存储库都有一个下载部分。如果您需要多个二进制文件,则可以使用.zip文件。
下载上传文件的网址是:

  https://github.com/downloads/user/repository / filename 

请注意,上面给出的URL来自 github上的链接。 com ,将重定向到 raw.githubusercontent.com 。您不应直接使用此HTTP 302重定向提供的网址,因为根据 RFC 2616 :由于重定向有时可能会发生变化,客户端应该继续使用请求URI来处理将来的请求。


I guess most of you, developers, use any VCS, and I hope some of you use Git. Do you have any tip or trick how to get a download URL for a single file in a repository?

I don't want the URL for displaying the raw file; in case of binaries it's for nothing.

http://support.github.com/discussions/feature-requests/41-download-single-file

Is it even possible to use GitHub as a "download server"?

If we decide to switch to Google Code, is the mentioned functionality presented here?

Or is there any free-of-charge hosting and VCS for open-source projects?

解决方案

Git does not support downloading parts of the repository. You have to download all of it. But you should be able to do this with GitHub.

When you view a file it has a link to the "raw" version. The URL is constructed like so

https://github.com/user/repository/raw/branch/filename

By filling in the blanks in the URL, you can use Wget or cURL (with the -L option, see below) or whatever to download a single file. Again, you won't get any of the nice version control features used by Git by doing this.

Update: I noticed you mention this doesn't work for binary files. You probably shouldn't use binary files in your Git repository, but GitHub has a download section for each repository that you can use to upload files. If you need more than one binary, you can use a .zip file. The URL to download an uploaded file is:

https://github.com/downloads/user/repository/filename

Note that the URLs given above, from the links on github.com, will redirect to raw.githubusercontent.com. You should not directly use the URL given by this HTTP 302 redirect because, per RFC 2616: "Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests."

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

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