Github API 下载包含 LFS 文件的 zipball/tarball

Github API to download a zipball/tarball which includes LFS files

我正在使用 v3 API 从 Git 集线器检索压缩包,即 https://api.github.com/repos/my-account/my-project/tarball/my-ref

但是,此项目对某些文件使用 Git-LFS,生成的存档不包含文件,但包含 LFS link:

version https://git-lfs.github.com/spec/v1
oid sha256:fc03a2eadf6ac4872de8ad96a865ed05c45c416c5ad40c9efa3c4bcbe5d0dc9e
size 1284

我该怎么做才能获得 LFS links 被真实文件内容替换的存档?

Git-lfs API 显示了如何以及在何处发出请求。 在您的情况下,假设您知道要查找的 OID(它存储在 pointer 中),您应该:

POST https://github.com/your-account/your-repo/objects 类似:

{
    "operation": "download",
    "objects": [
      {
       "oid": "fc03a2eadf6ac4872de8ad96a865ed05c45c416c5ad40c9efa3c4bcbe5d0dc9e",
       "size": 1284
      }
    ]
}

也许您可以省略 size 部分 - 它并没有真正指定。您也可以在 batch request

中同时请求多个 OIDs

响应看起来像 this 并且将包含指向 blob 本身的下载链接(如果它们存在)或每个 blob 的一些错误(如果整体响应总是 returns 为 200您已通过身份验证)。