Skip to main content
我们经常发布文档更新,此页面的翻译可能仍在进行中。 有关最新信息,请访问英语文档
REST API 现已经过版本控制。 有关详细信息,请参阅“关于 API 版本控制”。

Git LFS

使用 REST API 为存储库启用或禁用 Git Large File Storage (LFS)。

关于 Git LFS

可以使用 Git LFS 将大文件存储在 Git 存储库中。 使用 REST API 可以为单个存储库启用或禁用该功能。 有关 Git LFS 的详细信息,请参阅“关于 Git Large File Storage”。

对存储库具有管理员权限的人员可以使用这些终结点。

Git LFS 的使用需付费。 有关详细信息,请参阅“关于 Git Large File Storage 的计费”。

如果想要将这些终结点用于属于组织的存储库,你的角色必须提供对组织或企业计费的访问权限。

存储库所有权所需的存储库访问权限所需角色详细信息
个人帐户管理员空值空值
  • GitHub Team 上的组织
  • GitHub Enterprise Cloud 上的组织,但不在企业中
管理员,如果你是组织所有者,则会继承组织所有者或计费管理员"组织中的角色"
企业中的组织管理员,如果你是组织所有者,则可以继承企业所有者或计费管理员"企业中的角色"

Enable Git LFS for a repository

Enables Git LFS for a repository. Access tokens must have the admin:enterprise scope.

“Enable Git LFS for a repository”的参数

标头
名称, 类型, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
ownerstring必选

The account owner of the repository. The name is not case sensitive.

repostring必选

The name of the repository. The name is not case sensitive.

“Enable Git LFS for a repository”的 HTTP 响应状态代码

状态代码说明
202

Accepted

403

We will return a 403 with one of the following messages:

  • Git LFS support not enabled because Git LFS is globally disabled.
  • Git LFS support not enabled because Git LFS is disabled for the root repository in the network.
  • Git LFS support not enabled because Git LFS is disabled for .

“Enable Git LFS for a repository”的示例代码

put/repos/{owner}/{repo}/lfs
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>"\ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/lfs

Accepted

Disable Git LFS for a repository

Disables Git LFS for a repository. Access tokens must have the admin:enterprise scope.

“Disable Git LFS for a repository”的参数

标头
名称, 类型, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

路径参数
名称, 类型, 说明
ownerstring必选

The account owner of the repository. The name is not case sensitive.

repostring必选

The name of the repository. The name is not case sensitive.

“Disable Git LFS for a repository”的 HTTP 响应状态代码

状态代码说明
204

No Content

“Disable Git LFS for a repository”的示例代码

delete/repos/{owner}/{repo}/lfs
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>"\ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/lfs

Response

Status: 204