# Commits API
> 原文:[https://docs.gitlab.com/ee/api/commits.html](https://docs.gitlab.com/ee/api/commits.html)
* [List repository commits](#list-repository-commits)
* [Create a commit with multiple files and actions](#create-a-commit-with-multiple-files-and-actions)
* [Get a single commit](#get-a-single-commit)
* [Get references a commit is pushed to](#get-references-a-commit-is-pushed-to)
* [Cherry pick a commit](#cherry-pick-a-commit)
* [Revert a commit](#revert-a-commit)
* [Get the diff of a commit](#get-the-diff-of-a-commit)
* [Get the comments of a commit](#get-the-comments-of-a-commit)
* [Post comment to commit](#post-comment-to-commit)
* [Get the discussions of a commit](#get-the-discussions-of-a-commit)
* [Commit status](#commit-status)
* [List the statuses of a commit](#list-the-statuses-of-a-commit)
* [Post the build status to a commit](#post-the-build-status-to-a-commit)
* [List Merge Requests associated with a commit](#list-merge-requests-associated-with-a-commit)
* [Get GPG signature of a commit](#get-gpg-signature-of-a-commit)
# Commits API[](#commits-api "Permalink")
## List repository commits[](#list-repository-commits "Permalink")
获取项目中存储库提交的列表.
```
GET /projects/:id/repository/commits
```
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `ref_name` | string | no | 存储库分支的名称,标签或修订范围,或者如果未提供默认分支 |
| `since` | string | no | 仅此日期之后的提交将以 ISO 8601 格式返回 YYYY-MM-DDTHH:MM:SSZ |
| `until` | string | no | 仅在此日期之前或当天的提交将以 ISO 8601 格式返回 YYYY-MM-DDTHH:MM:SSZ |
| `path` | string | no | 文件路径 |
| `all` | boolean | no | 从存储库中检索每个提交 |
| `with_stats` | boolean | no | 有关每次提交的统计信息将添加到响应中 |
| `first_parent` | boolean | no | 看到合并提交后,仅关注第一个父提交 |
| `order` | string | no | 按顺序列出提交. 可能的值: `default` , [`topo`](https://git-scm.com/docs/git-log#Documentation/git-log.txt---topo-order) . 默认设置为`default` ,提交按时间倒序显示. |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits"
```
响应示例:
```
[ { "id": "ed899a2f4b50b4370feeea94676502b42383c746", "short_id": "ed899a2f4b5", "title": "Replace sanitize with escape once", "author_name": "Example User", "author_email": "user@example.com", "authored_date": "2012-09-20T11:50:22+03:00", "committer_name": "Administrator", "committer_email": "admin@example.com", "committed_date": "2012-09-20T11:50:22+03:00", "created_at": "2012-09-20T11:50:22+03:00", "message": "Replace sanitize with escape once", "parent_ids": [ "6104942438c14ec7bd21c6cd5bd995272b3faff6" ], "web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746" }, { "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", "short_id": "6104942438c", "title": "Sanitize for network graph", "author_name": "randx", "author_email": "user@example.com", "committer_name": "ExampleName", "committer_email": "user@example.com", "created_at": "2012-09-20T09:06:12+03:00", "message": "Sanitize for network graph", "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], "web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746" } ]
```
## Create a commit with multiple files and actions[](#create-a-commit-with-multiple-files-and-actions "Permalink")
在 GitLab 8.13 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/6096) .
通过发布 JSON 有效负载来创建提交
```
POST /projects/:id/repository/commits
```
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `branch` | string | yes | 要提交的分支名称. 要创建一个新分支,还提供`start_branch`或`start_sha` ,还可以提供`start_project` . |
| `commit_message` | string | yes | 提交讯息 |
| `start_branch` | string | no | 从中开始新分支的分支名称 |
| `start_sha` | string | no | 从以下位置启动新分支的提交的 SHA |
| `start_project` | integer/string | no | 从中开始新分支的项目 ID 或项目的[URL 编码路径](README.html#namespaced-path-encoding) . 默认为`id`的值. |
| `actions[]` | array | yes | 动作哈希数组要批量提交. 请参阅下表以了解它可以采用的属性. |
| `author_email` | string | no | 指定提交作者的电子邮件地址 |
| `author_name` | string | no | 指定提交作者的姓名 |
| `stats` | boolean | no | 包括提交统计信息. 默认为 true |
| `force` | boolean | no | 如果为`true`则基于`start_branch`或`start_sha`的新提交覆盖目标分支 |
| `actions[]` Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `action` | string | yes | 执行, `create` , `delete` , `move` , `update` , `chmod` |
| `file_path` | string | yes | 文件的完整路径. 例如 `lib/class.rb` |
| `previous_path` | string | no | 要移动文件的原始完整路径. 例如 `lib/class1.rb` . 仅考虑`move`动作. |
| `content` | string | no | 除`delete` , `chmod`和`move`以外的所有文件所必需的文件内容. 未指定`content`移动动作将保留现有文件内容,而任何其他`content`值都将覆盖文件内容. |
| `encoding` | string | no | `text`或`base64` . `text`是默认值. |
| `last_commit_id` | string | no | 上次已知的文件提交 ID. 仅在更新,移动和删除操作中考虑. |
| `execute_filemode` | boolean | no | 当为`true/false`启用/禁用文件上的 execute 标志. 仅考虑用于`chmod`操作. |
```
PAYLOAD=$(cat << 'JSON'
{
"branch": "master",
"commit_message": "some commit message",
"actions": [
{
"action": "create",
"file_path": "foo/bar",
"content": "some content"
},
{
"action": "delete",
"file_path": "foo/bar2"
},
{
"action": "move",
"file_path": "foo/bar3",
"previous_path": "foo/bar4",
"content": "some content"
},
{
"action": "update",
"file_path": "foo/bar5",
"content": "new content"
},
{
"action": "chmod",
"file_path": "foo/bar5",
"execute_filemode": true
}
]
} JSON )
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" --data "$PAYLOAD" "https://gitlab.example.com/api/v4/projects/1/repository/commits"
```
响应示例:
```
{ "id": "ed899a2f4b50b4370feeea94676502b42383c746", "short_id": "ed899a2f4b5", "title": "some commit message", "author_name": "Example User", "author_email": "user@example.com", "committer_name": "Example User", "committer_email": "user@example.com", "created_at": "2016-09-20T09:26:24.000-07:00", "message": "some commit message", "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], "committed_date": "2016-09-20T09:26:24.000-07:00", "authored_date": "2016-09-20T09:26:24.000-07:00", "stats": { "additions": 2, "deletions": 2, "total": 4 }, "status": null, "web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746" }
```
GitLab 支持[表单编码](README.html#encoding-api-parameters-of-array-and-hash-types) . 以下是使用 Commit API 和表单编码的示例:
```
curl --request POST \
--form "branch=master" \
--form "commit_message=some commit message" \
--form "start_branch=master" \
--form "actions[][action]=create" \
--form "actions[][file_path]=foo/bar" \
--form "actions[][content]=</path/to/local.file" \
--form "actions[][action]=delete" \
--form "actions[][file_path]=foo/bar2" \
--form "actions[][action]=move" \
--form "actions[][file_path]=foo/bar3" \
--form "actions[][previous_path]=foo/bar4" \
--form "actions[][content]=</path/to/local1.file" \
--form "actions[][action]=update" \
--form "actions[][file_path]=foo/bar5" \
--form "actions[][content]=</path/to/local2.file" \
--form "actions[][action]=chmod" \
--form "actions[][file_path]=foo/bar5" \
--form "actions[][execute_filemode]=true" \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/projects/1/repository/commits"
```
## Get a single commit[](#get-a-single-commit "Permalink")
获取由提交哈希或分支或标记的名称标识的特定提交.
```
GET /projects/:id/repository/commits/:sha
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交哈希或存储库分支或标记的名称 |
| `stats` | boolean | no | 包括提交统计信息. 默认为 true |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits/master"
```
响应示例:
```
{ "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", "short_id": "6104942438c", "title": "Sanitize for network graph", "author_name": "randx", "author_email": "user@example.com", "committer_name": "Dmitriy", "committer_email": "user@example.com", "created_at": "2012-09-20T09:06:12+03:00", "message": "Sanitize for network graph", "committed_date": "2012-09-20T09:06:12+03:00", "authored_date": "2012-09-20T09:06:12+03:00", "parent_ids": [ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba" ], "last_pipeline" : { "id": 8, "ref": "master", "sha": "2dc6aa325a317eda67812f05600bdf0fcdc70ab0", "status": "created" }, "stats": { "additions": 15, "deletions": 10, "total": 25 }, "status": "running", "web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/6104942438c14ec7bd21c6cd5bd995272b3faff6" }
```
## Get references a commit is pushed to[](#get-references-a-commit-is-pushed-to "Permalink")
在 GitLab 10.6 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/15026)
获取提交已提交的所有引用(从分支或标签). 分页参数`page`和`per_page`可用于限制引用列表.
```
GET /projects/:id/repository/commits/:sha/refs
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交哈希 |
| `type` | string | no | 提交范围. 可能的值是`branch` , `tag` , `all` . 默认为`all` . |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits/5937ac0a7beb003549fc5fd26fc247adbce4a52e/refs?type=all"
```
Example response:
```
[ {"type": "branch", "name": "'test'"}, {"type": "branch", "name": "add-balsamiq-file"}, {"type": "branch", "name": "wip"}, {"type": "tag", "name": "v1.1.0"} ]
```
## Cherry pick a commit[](#cherry-pick-a-commit "Permalink")
在 GitLab 8.15 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/8047) .
Cherry 选择了对给定分支的提交.
```
POST /projects/:id/repository/commits/:sha/cherry_pick
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交哈希 |
| `branch` | string | yes | 分支名称 |
```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "branch=master" "https://gitlab.example.com/api/v4/projects/5/repository/commits/master/cherry_pick"
```
响应示例:
```
{ "id": "8b090c1b79a14f2bd9e8a738f717824ff53aebad", "short_id": "8b090c1b", "title": "Feature added", "author_name": "Example User", "author_email": "user@example.com", "authored_date": "2016-12-12T20:10:39.000+01:00", "created_at": "2016-12-12T20:10:39.000+01:00", "committer_name": "Administrator", "committer_email": "admin@example.com", "committed_date": "2016-12-12T20:10:39.000+01:00", "title": "Feature added", "message": "Feature added\n\nSigned-off-by: Example User <user@example.com>\n", "parent_ids": [ "a738f717824ff53aebad8b090c1b79a14f2bd9e8" ], "web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad" }
```
如果选择失败,响应将提供有关以下原因的上下文:
```
{ "message": "Sorry, we cannot cherry-pick this commit automatically. This commit may already have been cherry-picked, or a more recent commit may have updated some of its content.", "error_code": "empty" }
```
在这种情况下,cherry-pick 失败,因为变更集为空,并且很可能表明提交已存在于目标分支中. 另一个可能的错误代码是`conflict` ,表示存在合并冲突.
## Revert a commit[](#revert-a-commit "Permalink")
在 GitLab 11.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/22919) .
恢复给定分支中的提交.
```
POST /projects/:id/repository/commits/:sha/revert
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交 SHA 还原 |
| `branch` | string | yes | 目标分支名称 |
```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "branch=master" "https://gitlab.example.com/api/v4/projects/5/repository/commits/a738f717824ff53aebad8b090c1b79a14f2bd9e8/revert"
```
响应示例:
```
{ "id":"8b090c1b79a14f2bd9e8a738f717824ff53aebad", "short_id": "8b090c1b", "title":"Revert \"Feature added\"", "created_at":"2018-11-08T15:55:26.000Z", "parent_ids":["a738f717824ff53aebad8b090c1b79a14f2bd9e8"], "message":"Revert \"Feature added\"\n\nThis reverts commit a738f717824ff53aebad8b090c1b79a14f2bd9e8", "author_name":"Administrator", "author_email":"admin@example.com", "authored_date":"2018-11-08T15:55:26.000Z", "committer_name":"Administrator", "committer_email":"admin@example.com", "committed_date":"2018-11-08T15:55:26.000Z", "web_url": "https://gitlab.example.com/thedude/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad" }
```
如果还原失败,则响应将提供有关以下原因的上下文:
```
{ "message": "Sorry, we cannot revert this commit automatically. This commit may already have been reverted, or a more recent commit may have updated some of its content.", "error_code": "conflict" }
```
在这种情况下,还原失败,因为尝试的还原产生了合并冲突. 另一个可能的错误代码为`empty` ,表明变更集为空,这可能是由于变更已被还原.
## Get the diff of a commit[](#get-the-diff-of-a-commit "Permalink")
获取项目中提交的差异.
```
GET /projects/:id/repository/commits/:sha/diff
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交哈希或存储库分支或标记的名称 |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits/master/diff"
```
响应示例:
```
[ { "diff": "--- a/doc/update/5.4-to-6.0.md\n+++ b/doc/update/5.4-to-6.0.md\n@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production\n+\n ```\n \n ### 6\. Update config files", "new_path": "doc/update/5.4-to-6.0.md", "old_path": "doc/update/5.4-to-6.0.md", "a_mode": null, "b_mode": "100644", "new_file": false, "renamed_file": false, "deleted_file": false } ]
```
## Get the comments of a commit[](#get-the-comments-of-a-commit "Permalink")
获取项目中提交的注释.
```
GET /projects/:id/repository/commits/:sha/comments
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交哈希或存储库分支或标记的名称 |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits/master/comments"
```
响应示例:
```
[ { "note": "this code is really nice", "author": { "id": 11, "username": "admin", "email": "admin@local.host", "name": "Administrator", "state": "active", "created_at": "2014-03-06T08:17:35.000Z" } } ]
```
## Post comment to commit[](#post-comment-to-commit "Permalink")
在提交中添加评论.
为了在特定文件的特定行中发布评论,您必须指定完整的提交 SHA, `path` , `line`和`line_type`应该是`new` .
如果以下至少一种情况有效,则注释将在最后一次提交的末尾添加:
* 相反, `sha`是分支或标签,并且`line`或`path`无效
* `line`号无效(不存在)
* `path`无效(不存在)
在上述任何情况下, `line` , `line_type`和`path`的响应都设置为`null` .
```
POST /projects/:id/repository/commits/:sha/comments
```
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交 SHA 或存储库分支或标记的名称 |
| `note` | string | yes | 评论文字 |
| `path` | string | no | 相对于存储库的文件路径 |
| `line` | integer | no | 放置评论的行号 |
| `line_type` | string | no | 线型. 采用`new`或`old`的争论 |
```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "note=Nice picture man\!" --form "path=dudeism.md" --form "line=11" --form "line_type=new" "https://gitlab.example.com/api/v4/projects/17/repository/commits/18f3e63d05582537db6d183d9d557be09e1f90c8/comments"
```
响应示例:
```
{ "author" : { "web_url" : "https://gitlab.example.com/thedude", "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png", "username" : "thedude", "state" : "active", "name" : "Jeff Lebowski", "id" : 28 }, "created_at" : "2016-01-19T09:44:55.600Z", "line_type" : "new", "path" : "dudeism.md", "line" : 11, "note" : "Nice picture man!" }
```
## Get the discussions of a commit[](#get-the-discussions-of-a-commit "Permalink")
获取项目中提交的讨论.
```
GET /projects/:id/repository/commits/:sha/discussions
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交哈希或存储库分支或标记的名称 |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits/4604744a1c64de00ff62e1e8a6766919923d2b41/discussions"
```
响应示例:
```
[ { "id": "4604744a1c64de00ff62e1e8a6766919923d2b41", "individual_note": true, "notes": [ { "id": 334686748, "type": null, "body": "I'm the Dude, so that's what you call me.", "attachment": null, "author" : { "id" : 28, "name" : "Jeff Lebowski", "username" : "thedude", "web_url" : "https://gitlab.example.com/thedude", "state" : "active", "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png" }, "created_at": "2020-04-30T18:48:11.432Z", "updated_at": "2020-04-30T18:48:11.432Z", "system": false, "noteable_id": null, "noteable_type": "Commit", "resolvable": false, "confidential": null, "noteable_iid": null, "commands_changes": {} } ] } ]
```
## Commit status[](#commit-status "Permalink")
从 GitLab 8.1 开始,这是新的提交状态 API.
### List the statuses of a commit[](#list-the-statuses-of-a-commit "Permalink")
列出项目中提交的状态. 分页参数`page`和`per_page`可用于限制引用列表.
```
GET /projects/:id/repository/commits/:sha/statuses
```
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交 SHA |
| `ref` | string | no | The name of a repository branch or tag or, if not given, the default branch |
| `stage` | string | no | 按[构建阶段](../ci/yaml/README.html#stages)过滤,例如`test` |
| `name` | string | no | 按[工作名称](../ci/yaml/README.html#introduction)过滤,例如`bundler:audit` |
| `all` | boolean | no | 返回所有状态,不仅是最新状态 |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/17/repository/commits/18f3e63d05582537db6d183d9d557be09e1f90c8/statuses
```
响应示例:
```
[ ... { "status" : "pending", "created_at" : "2016-01-19T08:40:25.934Z", "started_at" : null, "name" : "bundler:audit", "allow_failure" : true, "author" : { "username" : "thedude", "state" : "active", "web_url" : "https://gitlab.example.com/thedude", "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png", "id" : 28, "name" : "Jeff Lebowski" }, "description" : null, "sha" : "18f3e63d05582537db6d183d9d557be09e1f90c8", "target_url" : "https://gitlab.example.com/thedude/gitlab-foss/builds/91", "finished_at" : null, "id" : 91, "ref" : "master" }, { "started_at" : null, "name" : "test", "allow_failure" : false, "status" : "pending", "created_at" : "2016-01-19T08:40:25.832Z", "target_url" : "https://gitlab.example.com/thedude/gitlab-foss/builds/90", "id" : 90, "finished_at" : null, "ref" : "master", "sha" : "18f3e63d05582537db6d183d9d557be09e1f90c8", "author" : { "id" : 28, "name" : "Jeff Lebowski", "username" : "thedude", "web_url" : "https://gitlab.example.com/thedude", "state" : "active", "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png" }, "description" : null }, ... ]
```
### Post the build status to a commit[](#post-the-build-status-to-a-commit "Permalink")
添加或更新提交的构建状态.
```
POST /projects/:id/statuses/:sha
```
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交 SHA |
| `state` | string | yes | 状态的状态. 可以是以下之一: `pending` , `running` , `success` , `failed` , `canceled` |
| `ref` | string | no | 状态所`ref` (分支或标签) |
| `name` or `context` | string | no | 区分此状态和其他系统状态的标签. 默认值是`default` |
| `target_url` | string | no | 与该状态关联的目标 URL |
| `description` | string | no | 状态的简短描述 |
| `coverage` | float | no | 总代码覆盖率 |
| `pipeline_id` | integer | no | 要设置状态的管道的 ID. 在同一 SHA 上有多个管道的情况下使用. |
```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/17/statuses/18f3e63d05582537db6d183d9d557be09e1f90c8?state=success"
```
响应示例:
```
{ "author" : { "web_url" : "https://gitlab.example.com/thedude", "name" : "Jeff Lebowski", "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png", "username" : "thedude", "state" : "active", "id" : 28 }, "name" : "default", "sha" : "18f3e63d05582537db6d183d9d557be09e1f90c8", "status" : "success", "coverage": 100.0, "description" : null, "id" : 93, "target_url" : null, "ref" : null, "started_at" : null, "created_at" : "2016-01-19T09:05:50.355Z", "allow_failure" : false, "finished_at" : "2016-01-19T09:05:50.365Z" }
```
## List Merge Requests associated with a commit[](#list-merge-requests-associated-with-a-commit "Permalink")
在 GitLab 10.7 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/18004) .
获取与指定提交相关的合并请求列表.
```
GET /projects/:id/repository/commits/:sha/merge_requests
```
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交 SHA |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits/af5b13261899fb2c0db30abdd0af8b07cb44fdc5/merge_requests"
```
响应示例:
```
[ { "id":45, "iid":1, "project_id":35, "title":"Add new file", "description":"", "state":"opened", "created_at":"2018-03-26T17:26:30.916Z", "updated_at":"2018-03-26T17:26:30.916Z", "target_branch":"master", "source_branch":"test-branch", "upvotes":0, "downvotes":0, "author" : { "web_url" : "https://gitlab.example.com/thedude", "name" : "Jeff Lebowski", "avatar_url" : "https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png", "username" : "thedude", "state" : "active", "id" : 28 }, "assignee":null, "source_project_id":35, "target_project_id":35, "labels":[ ], "work_in_progress":false, "milestone":null, "merge_when_pipeline_succeeds":false, "merge_status":"can_be_merged", "sha":"af5b13261899fb2c0db30abdd0af8b07cb44fdc5", "merge_commit_sha":null, "squash_commit_sha":null, "user_notes_count":0, "discussion_locked":null, "should_remove_source_branch":null, "force_remove_source_branch":false, "web_url":"http://https://gitlab.example.com/root/test-project/merge_requests/1", "time_stats":{ "time_estimate":0, "total_time_spent":0, "human_time_estimate":null, "human_total_time_spent":null } } ]
```
## Get GPG signature of a commit[](#get-gpg-signature-of-a-commit "Permalink")
[从提交](../user/project/repository/gpg_signed_commits/index.html)获取[GPG 签名](../user/project/repository/gpg_signed_commits/index.html) (如果已签名). 对于未签名的提交,将导致 404 响应.
```
GET /projects/:id/repository/commits/:sha/signature
```
Parameters:
| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `sha` | string | yes | 提交哈希或存储库分支或标记的名称 |
```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/repository/commits/da738facbc19eb2fc2cef57c49be0e6038570352/signature"
```
如果提交是由 GPG 签名的,则示例响应:
```
{ "signature_type": "PGP", "verification_status": "verified", "gpg_key_id": 1, "gpg_key_primary_keyid": "8254AAB3FBD54AC9", "gpg_key_user_name": "John Doe", "gpg_key_user_email": "johndoe@example.com", "gpg_key_subkey_id": null }
```
如果提交是 X.509 签名的示例响应:
```
{ "signature_type": "X509", "verification_status": "unverified", "x509_certificate": { "id": 1, "subject": "CN=gitlab@example.org,OU=Example,O=World", "subject_key_identifier": "BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC", "email": "gitlab@example.org", "serial_number": 278969561018901340486471282831158785578, "certificate_status": "good", "x509_issuer": { "id": 1, "subject": "CN=PKI,OU=Example,O=World", "subject_key_identifier": "AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB", "crl_url": "http://example.com/pki.crl" } } }
```
如果提交是未签名的,示例响应:
```
{ "message": "404 GPG Signature Not Found" }
```
- GitLab Docs
- Installation
- Requirements
- GitLab cloud native Helm Chart
- Install GitLab with Docker
- Installation from source
- Install GitLab on Microsoft Azure
- Installing GitLab on Google Cloud Platform
- Installing GitLab on Amazon Web Services (AWS)
- Analytics
- Code Review Analytics
- Productivity Analytics
- Value Stream Analytics
- Kubernetes clusters
- Adding and removing Kubernetes clusters
- Adding EKS clusters
- Adding GKE clusters
- Group-level Kubernetes clusters
- Instance-level Kubernetes clusters
- Canary Deployments
- Cluster Environments
- Deploy Boards
- GitLab Managed Apps
- Crossplane configuration
- Cluster management project (alpha)
- Kubernetes Logs
- Runbooks
- Serverless
- Deploying AWS Lambda function using GitLab CI/CD
- Securing your deployed applications
- Groups
- Contribution Analytics
- Custom group-level project templates
- Epics
- Manage epics
- Group Import/Export
- Insights
- Issues Analytics
- Iterations
- Public access
- SAML SSO for GitLab.com groups
- SCIM provisioning using SAML SSO for GitLab.com groups
- Subgroups
- Roadmap
- Projects
- GitLab Secure
- Security Configuration
- Container Scanning
- Dependency Scanning
- Dependency List
- Static Application Security Testing (SAST)
- Secret Detection
- Dynamic Application Security Testing (DAST)
- GitLab Security Dashboard
- Offline environments
- Standalone Vulnerability pages
- Security scanner integration
- Badges
- Bulk editing issues and merge requests at the project level
- Code Owners
- Compliance
- License Compliance
- Compliance Dashboard
- Create a project
- Description templates
- Deploy Keys
- Deploy Tokens
- File finder
- Project integrations
- Integrations
- Atlassian Bamboo CI Service
- Bugzilla Service
- Custom Issue Tracker service
- Discord Notifications service
- Enabling emails on push
- GitHub project integration
- Hangouts Chat service
- Atlassian HipChat
- Irker IRC Gateway
- GitLab Jira integration
- Mattermost Notifications Service
- Mattermost slash commands
- Microsoft Teams service
- Mock CI Service
- Prometheus integration
- Redmine Service
- Slack Notifications Service
- Slack slash commands
- GitLab Slack application
- Webhooks
- YouTrack Service
- Insights
- Issues
- Crosslinking Issues
- Design Management
- Confidential issues
- Due dates
- Issue Boards
- Issue Data and Actions
- Labels
- Managing issues
- Milestones
- Multiple Assignees for Issues
- Related issues
- Service Desk
- Sorting and ordering issue lists
- Issue weight
- Associate a Zoom meeting with an issue
- Merge requests
- Allow collaboration on merge requests across forks
- Merge Request Approvals
- Browser Performance Testing
- How to create a merge request
- Cherry-pick changes
- Code Quality
- Load Performance Testing
- Merge Request dependencies
- Fast-forward merge requests
- Merge when pipeline succeeds
- Merge request conflict resolution
- Reverting changes
- Reviewing and managing merge requests
- Squash and merge
- Merge requests versions
- Draft merge requests
- Members of a project
- Migrating projects to a GitLab instance
- Import your project from Bitbucket Cloud to GitLab
- Import your project from Bitbucket Server to GitLab
- Migrating from ClearCase
- Migrating from CVS
- Import your project from FogBugz to GitLab
- Gemnasium
- Import your project from GitHub to GitLab
- Project importing from GitLab.com to your private GitLab instance
- Import your project from Gitea to GitLab
- Import your Jira project issues to GitLab
- Migrating from Perforce Helix
- Import Phabricator tasks into a GitLab project
- Import multiple repositories by uploading a manifest file
- Import project from repo by URL
- Migrating from SVN to GitLab
- Migrating from TFVC to Git
- Push Options
- Releases
- Repository
- Branches
- Git Attributes
- File Locking
- Git file blame
- Git file history
- Repository mirroring
- Protected branches
- Protected tags
- Push Rules
- Reduce repository size
- Signing commits with GPG
- Syntax Highlighting
- GitLab Web Editor
- Web IDE
- Requirements Management
- Project settings
- Project import/export
- Project access tokens (Alpha)
- Share Projects with other Groups
- Snippets
- Static Site Editor
- Wiki
- Project operations
- Monitor metrics for your CI/CD environment
- Set up alerts for Prometheus metrics
- Embedding metric charts within GitLab-flavored Markdown
- Embedding Grafana charts
- Using the Metrics Dashboard
- Dashboard YAML properties
- Metrics dashboard settings
- Panel types for dashboards
- Using Variables
- Templating variables for metrics dashboards
- Prometheus Metrics library
- Monitoring AWS Resources
- Monitoring HAProxy
- Monitoring Kubernetes
- Monitoring NGINX
- Monitoring NGINX Ingress Controller
- Monitoring NGINX Ingress Controller with VTS metrics
- Alert Management
- Error Tracking
- Tracing
- Incident Management
- GitLab Status Page
- Feature Flags
- GitLab CI/CD
- GitLab CI/CD pipeline configuration reference
- GitLab CI/CD include examples
- Introduction to CI/CD with GitLab
- Getting started with GitLab CI/CD
- How to enable or disable GitLab CI/CD
- Using SSH keys with GitLab CI/CD
- Migrating from CircleCI
- Migrating from Jenkins
- Auto DevOps
- Getting started with Auto DevOps
- Requirements for Auto DevOps
- Customizing Auto DevOps
- Stages of Auto DevOps
- Upgrading PostgreSQL for Auto DevOps
- Cache dependencies in GitLab CI/CD
- GitLab ChatOps
- Cloud deployment
- Docker integration
- Building Docker images with GitLab CI/CD
- Using Docker images
- Building images with kaniko and GitLab CI/CD
- GitLab CI/CD environment variables
- Predefined environment variables reference
- Where variables can be used
- Deprecated GitLab CI/CD variables
- Environments and deployments
- Protected Environments
- GitLab CI/CD Examples
- Test a Clojure application with GitLab CI/CD
- Using Dpl as deployment tool
- Testing a Phoenix application with GitLab CI/CD
- End-to-end testing with GitLab CI/CD and WebdriverIO
- DevOps and Game Dev with GitLab CI/CD
- Deploy a Spring Boot application to Cloud Foundry with GitLab CI/CD
- How to deploy Maven projects to Artifactory with GitLab CI/CD
- Testing PHP projects
- Running Composer and NPM scripts with deployment via SCP in GitLab CI/CD
- Test and deploy Laravel applications with GitLab CI/CD and Envoy
- Test and deploy a Python application with GitLab CI/CD
- Test and deploy a Ruby application with GitLab CI/CD
- Test and deploy a Scala application to Heroku
- GitLab CI/CD for external repositories
- Using GitLab CI/CD with a Bitbucket Cloud repository
- Using GitLab CI/CD with a GitHub repository
- GitLab Pages
- GitLab Pages
- GitLab Pages domain names, URLs, and baseurls
- Create a GitLab Pages website from scratch
- Custom domains and SSL/TLS Certificates
- GitLab Pages integration with Let's Encrypt
- GitLab Pages Access Control
- Exploring GitLab Pages
- Incremental Rollouts with GitLab CI/CD
- Interactive Web Terminals
- Optimizing GitLab for large repositories
- Metrics Reports
- CI/CD pipelines
- Pipeline Architecture
- Directed Acyclic Graph
- Multi-project pipelines
- Parent-child pipelines
- Pipelines for Merge Requests
- Pipelines for Merged Results
- Merge Trains
- Job artifacts
- Pipeline schedules
- Pipeline settings
- Triggering pipelines through the API
- Review Apps
- Configuring GitLab Runners
- GitLab CI services examples
- Using MySQL
- Using PostgreSQL
- Using Redis
- Troubleshooting CI/CD
- GitLab Package Registry
- GitLab Container Registry
- Dependency Proxy
- GitLab Composer Repository
- GitLab Conan Repository
- GitLab Maven Repository
- GitLab NPM Registry
- GitLab NuGet Repository
- GitLab PyPi Repository
- API Docs
- API resources
- .gitignore API
- GitLab CI YMLs API
- Group and project access requests API
- Appearance API
- Applications API
- Audit Events API
- Avatar API
- Award Emoji API
- Project badges API
- Group badges API
- Branches API
- Broadcast Messages API
- Project clusters API
- Group clusters API
- Instance clusters API
- Commits API
- Container Registry API
- Custom Attributes API
- Dashboard annotations API
- Dependencies API
- Deploy Keys API
- Deployments API
- Discussions API
- Dockerfiles API
- Environments API
- Epics API
- Events
- Feature Flags API
- Feature flag user lists API
- Freeze Periods API
- Geo Nodes API
- Group Activity Analytics API
- Groups API
- Import API
- Issue Boards API
- Group Issue Boards API
- Issues API
- Epic Issues API
- Issues Statistics API
- Jobs API
- Keys API
- Labels API
- Group Labels API
- License
- Licenses API
- Issue links API
- Epic Links API
- Managed Licenses API
- Markdown API
- Group and project members API
- Merge request approvals API
- Merge requests API
- Project milestones API
- Group milestones API
- Namespaces API
- Notes API
- Notification settings API
- Packages API
- Pages domains API
- Pipeline schedules API
- Pipeline triggers API
- Pipelines API
- Project Aliases API
- Project import/export API
- Project repository storage moves API
- Project statistics API
- Project templates API
- Projects API
- Protected branches API
- Protected tags API
- Releases API
- Release links API
- Repositories API
- Repository files API
- Repository submodules API
- Resource label events API
- Resource milestone events API
- Resource weight events API
- Runners API
- SCIM API
- Search API
- Services API
- Application settings API
- Sidekiq Metrics API
- Snippets API
- Project snippets
- Application statistics API
- Suggest Changes API
- System hooks API
- Tags API
- Todos API
- Users API
- Project-level Variables API
- Group-level Variables API
- Version API
- Vulnerabilities API
- Vulnerability Findings API
- Wikis API
- GraphQL API
- Getting started with GitLab GraphQL API
- GraphQL API Resources
- API V3 to API V4
- Validate the .gitlab-ci.yml (API)
- User Docs
- Abuse reports
- User account
- Active sessions
- Deleting a User account
- Permissions
- Personal access tokens
- Profile preferences
- Threads
- GitLab and SSH keys
- GitLab integrations
- Git
- GitLab.com settings
- Infrastructure as code with Terraform and GitLab
- GitLab keyboard shortcuts
- GitLab Markdown
- AsciiDoc
- GitLab Notification Emails
- GitLab Quick Actions
- Autocomplete characters
- Reserved project and group names
- Search through GitLab
- Advanced Global Search
- Advanced Syntax Search
- Time Tracking
- GitLab To-Do List
- Administrator Docs
- Reference architectures
- Reference architecture: up to 1,000 users
- Reference architecture: up to 2,000 users
- Reference architecture: up to 3,000 users
- Reference architecture: up to 5,000 users
- Reference architecture: up to 10,000 users
- Reference architecture: up to 25,000 users
- Reference architecture: up to 50,000 users
- Troubleshooting a reference architecture set up
- Working with the bundled Consul service
- Configuring PostgreSQL for scaling
- Configuring GitLab application (Rails)
- Load Balancer for multi-node GitLab
- Configuring a Monitoring node for Scaling and High Availability
- NFS
- Working with the bundled PgBouncer service
- Configuring Redis for scaling
- Configuring Sidekiq
- Admin Area settings
- Continuous Integration and Deployment Admin settings
- Custom instance-level project templates
- Diff limits administration
- Enable and disable GitLab features deployed behind feature flags
- Geo nodes Admin Area
- GitLab Pages administration
- Health Check
- Job logs
- Labels administration
- Log system
- PlantUML & GitLab
- Repository checks
- Repository storage paths
- Repository storage types
- Account and limit settings
- Service templates
- System hooks
- Changing your time zone
- Uploads administration
- Abuse reports
- Activating and deactivating users
- Audit Events
- Blocking and unblocking users
- Broadcast Messages
- Elasticsearch integration
- Gitaly
- Gitaly Cluster
- Gitaly reference
- Monitoring GitLab
- Monitoring GitLab with Prometheus
- Performance Bar
- Usage statistics
- Object Storage
- Performing Operations in GitLab
- Cleaning up stale Redis sessions
- Fast lookup of authorized SSH keys in the database
- Filesystem Performance Benchmarking
- Moving repositories managed by GitLab
- Run multiple Sidekiq processes
- Sidekiq MemoryKiller
- Switching to Puma
- Understanding Unicorn and unicorn-worker-killer
- User lookup via OpenSSH's AuthorizedPrincipalsCommand
- GitLab Package Registry administration
- GitLab Container Registry administration
- Replication (Geo)
- Geo database replication
- Geo with external PostgreSQL instances
- Geo configuration
- Using a Geo Server
- Updating the Geo nodes
- Geo with Object storage
- Docker Registry for a secondary node
- Geo for multiple nodes
- Geo security review (Q&A)
- Location-aware Git remote URL with AWS Route53
- Tuning Geo
- Removing secondary Geo nodes
- Geo data types support
- Geo Frequently Asked Questions
- Geo Troubleshooting
- Geo validation tests
- Disaster Recovery (Geo)
- Disaster recovery for planned failover
- Bring a demoted primary node back online
- Automatic background verification
- Rake tasks
- Back up and restore GitLab
- Clean up
- Namespaces
- Maintenance Rake tasks
- Geo Rake Tasks
- GitHub import
- Import bare repositories
- Integrity check Rake task
- LDAP Rake tasks
- Listing repository directories
- Praefect Rake tasks
- Project import/export administration
- Repository storage Rake tasks
- Generate sample Prometheus data
- Uploads migrate Rake tasks
- Uploads sanitize Rake tasks
- User management
- Webhooks administration
- X.509 signatures
- Server hooks
- Static objects external storage
- Updating GitLab
- GitLab release and maintenance policy
- Security
- Password Storage
- Custom password length limits
- Restrict allowed SSH key technologies and minimum length
- Rate limits
- Webhooks and insecure internal web services
- Information exclusivity
- How to reset your root password
- How to unlock a locked user from the command line
- User File Uploads
- How we manage the TLS protocol CRIME vulnerability
- User email confirmation at sign-up
- Security of running jobs
- Proxying assets
- CI/CD Environment Variables
- Contributor and Development Docs
- Contribute to GitLab
- Community members & roles
- Implement design & UI elements
- Issues workflow
- Merge requests workflow
- Code Review Guidelines
- Style guides
- GitLab Architecture Overview
- CI/CD development documentation
- Database guides
- Database Review Guidelines
- Database Review Guidelines
- Migration Style Guide
- What requires downtime?
- Understanding EXPLAIN plans
- Rake tasks for developers
- Mass inserting Rails models
- GitLab Documentation guidelines
- Documentation Style Guide
- Documentation structure and template
- Documentation process
- Documentation site architecture
- Global navigation
- GitLab Docs monthly release process
- Telemetry Guide
- Usage Ping Guide
- Snowplow Guide
- Experiment Guide
- Feature flags in development of GitLab
- Feature flags process
- Developing with feature flags
- Feature flag controls
- Document features deployed behind feature flags
- Frontend Development Guidelines
- Accessibility & Readability
- Ajax
- Architecture
- Axios
- Design Patterns
- Frontend Development Process
- DropLab
- Emojis
- Filter
- Frontend FAQ
- GraphQL
- Icons and SVG Illustrations
- InputSetter
- Performance
- Principles
- Security
- Tooling
- Vuex
- Vue
- Geo (development)
- Geo self-service framework (alpha)
- Gitaly developers guide
- GitLab development style guides
- API style guide
- Go standards and style guidelines
- GraphQL API style guide
- Guidelines for shell commands in the GitLab codebase
- HTML style guide
- JavaScript style guide
- Migration Style Guide
- Newlines style guide
- Python Development Guidelines
- SCSS style guide
- Shell scripting standards and style guidelines
- Sidekiq debugging
- Sidekiq Style Guide
- SQL Query Guidelines
- Vue.js style guide
- Instrumenting Ruby code
- Testing standards and style guidelines
- Flaky tests
- Frontend testing standards and style guidelines
- GitLab tests in the Continuous Integration (CI) context
- Review Apps
- Smoke Tests
- Testing best practices
- Testing levels
- Testing Rails migrations at GitLab
- Testing Rake tasks
- End-to-end Testing
- Beginner's guide to writing end-to-end tests
- End-to-end testing Best Practices
- Dynamic Element Validation
- Flows in GitLab QA
- Page objects in GitLab QA
- Resource class in GitLab QA
- Style guide for writing end-to-end tests
- Testing with feature flags
- Translate GitLab to your language
- Internationalization for GitLab
- Translating GitLab
- Proofread Translations
- Merging translations from CrowdIn
- Value Stream Analytics development guide
- GitLab subscription
- Activate GitLab EE with a license