简体   繁体   English

下载 github 用 curl 发布

[英]Download github release with curl

On this URL I'm able to download a.tar.gz which contains an official release.这个 URL 上,我可以下载包含官方版本的 a.tar.gz。 (I know it's also available on an API endpoint but this contains the test package too. (我知道它也可以在 API 端点上使用,但它也包含测试 package。

Now I'm wondering why this isn't working:现在我想知道为什么这不起作用:

$ curl -O https://github.com/yarnpkg/yarn/releases/download/v0.23.4/yarn-v0.23.4.tar.gz

I get some .tar.gz which is 4KB instead of 3.6MB.我得到一些.tar.gz ,它是 4KB 而不是 3.6MB。 It isn't showing an error.它没有显示错误。 What am I missing?我错过了什么? I want to use this URL and not the API if that's possible.如果可能的话,我想使用这个 URL 而不是 API。

If you do the following it will download correctly:如果您执行以下操作,它将正确下载:

wget https://github.com/yarnpkg/yarn/releases/download/v0.23.4/yarn-v0.23.4.tar.gz

If you want to use curl you have to use the redirect -L option to follow redirect link and direct the output in a file like this:如果你想使用 curl,你必须使用 redirect -L选项来跟随重定向链接并将输出定向到这样的文件中:

curl -L https://github.com/yarnpkg/yarn/releases/download/v0.23.4/ya‌​rn-v0.23.4.tar.gz > yarn.tar.gz

2021 Update Download from GitHub Using wget使用 wget 从 GitHub 下载 2021 更新

Will also expand and delete the archive.还将展开和删除存档。 Just edit the REPLACE_ values and then copy/paste只需编辑 REPLACE_ 值,然后复制/粘贴

tgz tgz

GH_USER=REPLACE_WITH_USER \
GH_REPO=REPLACE_WITH_REPO \
GH_BRANCH=REPLACE_WITH_BRANCH \
wget https://github.com/${GH_USER}/${GH_REPO}/archive/refs/tags/${GH_BRANCH}.tar.gz \
-O "${GH_REPO}-${GH_BRANCH}.tar.gz" && \
tar -xzvf ./"${GH_REPO}-${GH_BRANCH}.tar.gz" && \
rm ./"${GH_REPO}-${GH_BRANCH}.tar.gz"

zip压缩

GH_USER=REPLACE_WITH_USER \
GH_REPO=REPLACE_WITH_REPO \
GH_BRANCH=REPLACE_WITH_BRANCH \
wget https://github.com/${GH_USER}/${GH_REPO}/archive/refs/tags/${GH_BRANCH}.zip \
-O "${GH_REPO}-${GH_BRANCH}.zip" && \ 
unzip ./"${GH_REPO}-${GH_BRANCH}.zip" && \
rm ./"${GH_REPO}-${GH_BRANCH}.zip"

I hope this helps someone: make sure your repository is public .我希望这对某人有所帮助:确保您的存储库是public

Then as explained in the other answers this should work:然后正如其他答案中所解释的那样,这应该可以工作:

curl -LO 'https://github.com/<user>/<repo>/archive/refs/tags/<1.0.0>.tar.gz'

When private, a token is required to access the release files, and you'll get NOT FOUND as a response.私有时,访问发布文件需要令牌,并且您将得到NOT FOUND作为响应。 That was my issue.那是我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM