从GitHub repo下载单个文件有哪些技巧?

我不想要显示原始文件的URL;对于二进制文件,什么都没有。

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

是否有可能将GitHub用作“下载服务器”?

如果我们决定切换到GoogleCode,是否提供了上述功能?

或者开源项目是否有免费托管和VCS?


当前回答

为了跟进thomasfuchs所说的,但对于GitHub Enterprise用户,您可以使用以下内容。

curl-H'授权:令牌INSERTACCESSTOKENHERE'-H'接受:application/vnd.github.v3.raw'-O-Lhttps://your_domain/api/v3/repos/owner/repo/contents/path

这里还有API文档https://developer.github.com/v3/repos/contents

其他回答

要从Github repo下载文件,请使用带有原始文件链接的“curl”命令。

curl https://raw.githubusercontent.com/user/repo/filename --output filename

添加--output选项,后跟新文件名,将原始文件下载到新创建的文件中。

您应该只使用文件的原始URL进行操作。

例如,下载AFNetworking的README:

curl https://raw.githubusercontent.com/AFNetworking/AFNetworking/master/README.md > ADREADME.md 

由于它是公共回购,因此您不需要任何凭据。请注意url的类型:raw.githubusercontent.com/path/to/file

现在,这在GitHub中可以用于任何文件。您需要翻译raw.github.com的文件。例如,如果您的文件位于存储库中:

https://github.com/<username>/<repo>/some_directory/file.rb

使用wget,您可以从以下位置获取原始文件:

https://raw.github.com/<username>/<repo>/<branch>/some_directory/file.rb

Rails Composer就是一个很好的例子。

现在,可以使用以下google chrome扩展名下载存储库中的任何文件或任何特定文件夹:

github的GitZip:链接:https://chrome.google.com/webstore/detail/gitzip-for-github/ffabmkklhbepgcgfonabamgnfafbdlkn

用法:

在任何GitHub公共repo页面中。只需双击所需的项目。单击右下角的下载按钮。查看进度仪表板并等待浏览器触发器下载。获取ZIP文件。

只需将wget与raw=True参数一起使用

wget "https://github.com/user/repository/blob/master/directory/file_name?raw=True" -O target_path/file_name