如何使用命令行从私有 github 存储库下载单个原始文件? [英] How can I download a single raw file from a private github repo using the command line?

查看:27
本文介绍了如何使用命令行从私有 github 存储库下载单个原始文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 CI 服务器上,我想获取我们在 Github 上维护的配置文件,以便它可以在许多作业之间共享.我正在尝试通过 curl 获取这个文件,但是这些方法都失败了(我得到了 404):

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).

您可以使用 V3 API 来获取这样的原始文件(您需要一个 OAuth 令牌):

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

所有这些都必须在一行上进行.-O 选项将文件保存在当前目录中.您可以使用 -o filename 指定不同的文件名.

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.

要获取 OAuth 令牌,请按照此处的说明进行操作:

To get the OAuth token follow the instructions here:

我也把它写成一个要点:

I've written this up as a gist as well:

解决方案的 API 参考如下:

API references for the solution are as follows:

这篇关于如何使用命令行从私有 github 存储库下载单个原始文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆