从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 Mate可以轻松下载单个文件,只需单击图标即可下载,目前它只能在Chrome上运行。

对于使用GitHub Enterprise的用户,您需要按照以下方案构造URL

调用WebRequesthttp://github.mycompany.com/api/v3/repos/my-org/my-repo/contents/myfiles/file.txt-标头@{“Authorization”=“token 8d795936d2c1b2806587719b9b6456bd16549ad8”}

详细信息可在此处找到

http://artisticcheese.blogspot.com/2017/04/how-to-download-individual-files-from.html

可以这样使用curl:

卷曲-OLhttps://raw.githubusercontent.com/<username>/<repo名称>/<branch名称>/path/to/file

O表示curl下载内容L表示卷曲遵循重定向

现在,这在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就是一个很好的例子。

在Mac或Linux上安装jq并使用它从Github中提取文件,如下所示:

curl -H 'Authorization: token <ACCESS_TOKEN>' \
   -H "Accept: application/vnd.github.v3+raw" -L \
   https://api.github.com/repos/MY-ORG/MY-REPO/contents/MY-FILE-PATH | \
   jq -r '.content' | base64 --decode > MY_FILE_NAME.txt

可以在此处找到上述命令的文档。