如何使用 cURL 从 GitHub 下载 tarball?
我正在尝试使用 cURL 从 GitHub 下载 tarball,但它似乎没有重定向:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2
<html><body>You are being <a href="https://nodeload.github.com/pinard/Pymacs/tarball/v0.24-beta2">redirected</a>.</body></html>
注意:wget对我有用:
$ wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2
但是我想使用cURL,因为最终我想用类似的内容解压它:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
我发现重定向后的URL变成了 https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar .gz,但我希望 cURL 足够聪明来解决这个问题。
I am trying to download a tarball from GitHub using cURL, but it does not seem to be redirecting:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2
<html><body>You are being <a href="https://nodeload.github.com/pinard/Pymacs/tarball/v0.24-beta2">redirected</a>.</body></html>
Note: wget works for me:
$ wget --no-check-certificate https://github.com/pinard/Pymacs/tarball/v0.24-beta2
However I want to use cURL because ultimately I want to untar it inline with something like:
$ curl --insecure https://github.com/pinard/Pymacs/tarball/v0.24-beta2 | tar zx
I found that the URL after redirecting turned out to be https://download.github.com/pinard-Pymacs-v0.24-beta1-0-gcebc80b.tar.gz, but I would like cURL to be smart enough to figure this out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用
-L
选项来跟踪重定向:Use the
-L
option to follow redirects:现代化的方法是:
相应地替换
user-or-org
、repo
和sha1-or-ref
。如果您想要 zip 文件而不是 tarball,请指定
.zip
而不是.tar.gz
后缀。您还可以通过为curl指定
-u token:x-oauth-basic
选项来检索私有存储库的存档。将token
替换为 个人访问令牌。The modernized way of doing this is:
Replace
user-or-org
,repo
, andsha1-or-ref
accordingly.If you want a zip file instead of a tarball, specify
.zip
instead of.tar.gz
suffix.You can also retrieve the archive of a private repo, by specifying
-u token:x-oauth-basic
option to curl. Replacetoken
with a personal access token.您还可以使用 wget 来“内联解压”。只需将 stdout 指定为输出文件 (
-O -
):You can also use wget to »untar it inline«. Simply specify stdout as the output file (
-O -
):所有其他解决方案都需要指定发布/版本号,这显然会破坏自动化。
此解决方案 - 目前经过测试,已知可与 Github API v3 配合使用 - 但可以通过编程方式使用来获取 最新 版本,而无需指定任何标签或版本号并将二进制文件解压缩为您在开关
--one-top-level="pi-ap"
中指定的任意名称。只需在下面的示例中使用您自己的详细信息交换用户 f1linux 和存储库 pi-ap ,而 Bob 是您的叔叔:All the other solutions require specifying a release/version number which obviously breaks automation.
This solution- currently tested and known to work with Github API v3- however can be used programmatically to grab the LATEST release without specifying any tag or release number and un-TARs the binary to an arbitrary name you specify in switch
--one-top-level="pi-ap"
. Just swap-out user f1linux and repo pi-ap in below example with your own details and Bob's your uncle:具有特定的目录:
with a specific dir: