如何从 Github 下载 tarball

Ale*_*lls 3 tar curl github

我有这个:

curl -L "https://github.com/cmtr/cp-go-api/tarball/$commit_id" | tar x -C "$project_dir/"
Run Code Online (Sandbox Code Playgroud)

我只是想从 github 下载一个 tarball 并将其解压缩到现有目录。问题是我收到此错误:

Step 10/13 : RUN curl -L "https://github.com/channelmeter/cp-go-api/tarball/$commit_id" | tar x -C "$project_dir/"
 ---> Running in a883449de956
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100     9  100     9    0     0     35      0 --:--:-- --:--:-- --:--:--    35
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
The command '/bin/sh -c curl -L "https://github.com/channelmeter/cp-go-api/tarball/$commit_id" | tar x -C "$project_dir/"' returned a non-zero code: 2
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么它不是 tar 存档?如果您在浏览器中访问 github.com 并输入此模式,它将下载 tar.gz 存档:

https://github.com/<org>/<repo>/tarball/<sha>
Run Code Online (Sandbox Code Playgroud)

所以不知道为什么它不起作用。

Ale*_*lls 5

所以最终是因为 Github 想要凭据。没有 2-factor auth,你可以用 curl 来做到这一点:

curl -u username:password https://github.com/<org>/<repo>/tarball/<sha>
Run Code Online (Sandbox Code Playgroud)

但是如果您有 2-factor auth 设置,那么您需要使用 Github 访问令牌,并且您应该使用 api.github.com 而不是 github.com,如下所示:

 curl -L "https://api.github.com/repos/<org>/<repo>/tarball/$commit_sha?access_token=$github_token" | tar -xz -C "$extract_dir/"
Run Code Online (Sandbox Code Playgroud)

访问令牌的内容记录在这里:https : //help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line