如何从一个私人github仓库使用命令行下载一个单一的原始文件? [英] How can I download a single raw file from a private github repo using the command line?
问题描述
在CI服务器上,我想获取一个我们在Github上维护的配置文件,以便它可以在多个作业之间共享。我试图通过curl获得这个文件,但这些方法都失败了(我得到一个404):
#如建议通过oAuth docs
curl -H'授权:令牌the_token'-L -o setup.sh https://raw.github.com/org/repo/file
#网址的原始文件点击查看
curl -L https://raw.github.com/org/repo/file?login=username&token=the_token
解决方案以前的答案无效(或不再工作)。
您可以使用V3 API获取这样的原始文件(您需要一个OAuth令牌):
curl -H'授权:token INSERTACCESSTOKENHERE'-H'Accept:application / vnd.github.v3.raw'-O -L https://api.github.com/repos/owner/repo/contents/path
所有这一切都必须在一行。
-O
选项将文件保存在当前目录中。您可以使用-o filename
指定不同的文件名。
要获取OAuth令牌,
https://help.github.com/articles/创建一个访问令牌的命令行使用
我也写了一个gist:
https://gist.github.com/madrobby/9476733
EDIT:解决方案的API参考如下:
- https://developer.github.com/v3/#authentication
- https://developer.github.com/v3/media/#request-specific-version
- https://developer.github.com/v3/repos/contents/#get-contents li>
On the CI server, I want to fetch a config file that we maintain on Github so it can be shared between many jobs. I'm trying to get this file via curl, but these approaches both fail (I get a 404):
# As advised by the oAuth docs
curl -H 'Authorization: token the_token' -L -o setup.sh https://raw.github.com/org/repo/file
# The url of the raw file after clicking to view it
curl -L https://raw.github.com/org/repo/file?login=username&token=the_token
The previous answers don't work (or don't work anymore).
You can use the V3 API to get a raw file like this (you'll need an OAuth token):
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path
All of this has to go on one line. The -O
option saves the file in the current directory. You can use -o filename
to specify a different filename.
To get the OAuth token follow the instructions here: https://help.github.com/articles/creating-an-access-token-for-command-line-use
I've written this up as a gist as well: https://gist.github.com/madrobby/9476733
EDIT: API references for the solution are as follows:
- https://developer.github.com/v3/#authentication
- https://developer.github.com/v3/media/#request-specific-version
- https://developer.github.com/v3/repos/contents/#get-contents
这篇关于如何从一个私人github仓库使用命令行下载一个单一的原始文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!