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

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

问题描述

我想你们中的大多数人,开发者,使用任何VCS,我希望你们中的一些人使用 Git.您是否有任何提示或技巧来获取存储库中单个文件的下载 URL?

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?

我不想要显示原始文件的 URL;在二进制文件的情况下,它毫无意义.

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

http://support.github.com/discussions/功能请求/41-download-single-file

是否可以将 GitHub 用作下载服务器"?

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

如果我们决定改用 Google Code,这里是否提供了上述功能?

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

或者有免费的开源项目托管和VCS吗?

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

推荐答案

Git 不支持下载部分存储库.您必须下载所有内容.但是您应该可以使用 GitHub 来做到这一点.

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.

当您查看一个文件时,它有一个指向原始"文件的链接.版本.URL 是这样构造的

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

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

通过填写 URL 中的空白,您可以使用 WgetcURL(使用 -L 选项,见下文)或任何下载单个文件的文件.同样,您不会通过这样做获得 Git 使用的任何不错的版本控制功能.

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.

更新:我注意到您提到这不适用于二进制文件.您可能不应该在您的 Git 存储库中使用二进制文件,但 GitHub 为每个存储库提供了一个下载部分,您可以使用它来上传文件.如果您需要多个二进制文件,您可以使用 .zip 文件.下载上传文件的 URL 是:

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

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

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天全站免登陆