Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

git - 从GitHub下载单个文件(Download single files from GitHub)

I guess most of you, developers, use any VCS , and I hope some of you use Git.

(我想你们中的大多数开发人员都使用任何VCS ,并且希望你们中的一些人使用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;

(我不希望显示原始文件的URL。)

in case of binaries it's for nothing.

(如果是二进制文件,那是没有用的。)

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

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

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

(甚至可以将GitHub用作“下载服务器”吗?)

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

(如果我们决定切换到Google Code,是否在此提供了上述功能?)

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

(还是为开源项目提供免费的托管和VCS?)

  ask by Radek Simko translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Git does not support downloading parts of the repository.

(Git不支持下载存储库的某些部分。)

You have to download all of it.

(您必须全部下载。)

But you should be able to do this with GitHub.

(但是您应该能够使用GitHub做到这一点。)

When you view a file it has a link to the "raw" version.

(当您查看文件时,它具有指向“原始”版本的链接。)

The URL is constructed like so

(URL的结构如下)

https://raw.githubusercontent.com/user/repository/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.

(通过填写URL中的空格,您可以使用WgetcURL (带有-L选项,请参见下文)或下载单个文件的任何方法。)

Again, you won't get any of the nice version control features used by Git by doing this.

(同样,这样做不会获得Git使用的任何出色的版本控制功能。)

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.

(您可能不应该在Git存储库中使用二进制文件,但是GitHub为每个存储库提供了一个下载部分,您可以使用该部分来上传文件。)

If you need more than one binary, you can use a .zip file.

(如果需要多个二进制文件,则可以使用.zip文件。)

The URL to download an uploaded file is:

(下载上载文件的URL为:)

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 .

(请注意,上面给出的URL(来自github.com上的链接)将重定向到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."

(您不应该直接使用此HTTP 302重定向给出的URL,因为根据RFC 2616 :“由于重定向有时可能会更改,因此客户端应继续将Request-URI用于将来的请求。”)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...