Use this API to manage Git commits.
List all repository commits
GET /api/v4/projects/{id}/repository/commits
Lists all commits for a specified project repository.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
ref_Query | String | Name of a repository branch, Example: v1. |
sinceQuery | String (date- | Only commits after or on this date are returned Example: 2021- |
untilQuery | String (date- | Only commits before or on this date are returned Example: 2021- |
pathQuery | String | File path relative to the repository Example: README. |
followQuery | Boolean | If true,path and returns commits for the file even if it was renamed.false,path specifies a single file.true. |
authorQuery | String | Filter commits by commit author Example: John Smith |
allQuery | Boolean | If true,ref_ parameter |
with_Query | Boolean | If true, |
first_Query | Boolean | If true, |
orderQuery | String | Order in which to list commits, Allowed values: default,topoDefault: default |
trailersQuery | Boolean | If true,Default: false |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
paginationQuery | String | Specify the pagination method Allowed values: legacy,keysetDefault: legacy |
page_Query | String | Record from which to start the keyset pagination |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad request | — |
401 | Unauthorized | — |
404 | Not found | — |
Create a commit
POST /api/v4/projects/{id}/repository/commits
Creates a commit in the specified project from a JSON payload. The request body can also be form-encoded, with each action sent as actions[][<attribute>] fields. By default, requests larger than 300 MB are rejected. Requests larger than 20 MB are rate-limited to 3 requests every 30 seconds for each user. This feature was introduced in GitLab 8.13
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
Request body (multipart/form-data)
| Property | Type | Description |
|---|---|---|
fileRequired | String (binary) | The commit content to be created (generated by Multipart middleware) |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not found | — |
Retrieve a commit
GET /api/v4/projects/{id}/repository/commits/{sha}
Retrieves a specified commit identified by the commit hash or name of a branch or tag.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA or name of a repository branch or tag |
statsQuery | Boolean | If true,Default: true |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Cherry-pick a commit
POST /api/v4/projects/{id}/repository/commits/{sha}/cherry_pick
Cherry-picks a commit to a specified branch. If the cherry-pick fails, the 400 response contains a message and an error_code. The error_code is empty when the changeset is empty, which usually means the commit already exists in the target branch, or conflict when there is a merge conflict. If dry_run is true, a successful check returns {"dry_run": "success"}, and a failed check returns the same error response with "dry_run": "error" added.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA, |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
branchRequired | String | Name of the branch Example: master |
dry_ | Boolean | If true,Default: false |
message | String | Custom commit message to use for the new commit Example: Initial commit |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad request | — |
404 | Not found | — |
List all commit comments
GET /api/v4/projects/{id}/repository/commits/{sha}/comments
Lists all the comments of a commit in a project.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
shaPath, | String | Commit SHA or name of a repository branch or tag |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Create a comment on a commit
POST /api/v4/projects/{id}/repository/commits/{sha}/comments
Creates a comment on a commit. To comment on a specific line in a file, specify the full commit SHA, path, line, and set line_type to new. If path or line does not exist in the commit diff, the comment is added to the commit without a line position, and line, line_type, and path are null in the response. GitLab might change the comment body before saving it, for example by running and removing quick actions.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA or name of a repository branch or tag |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
lineRequired | Integer | Line number where the comment should be placed.path is providedExample: 11 |
line_Required | String | Line type Allowed values: new,oldDefault: newMinimum length: 1 |
noteRequired | String | Text of the comment Example: Nice code! |
path | String | File path relative to the repository Example: doc/ |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad request | — |
404 | Not found | — |
Retrieve a commit diff
GET /api/v4/projects/{id}/repository/commits/{sha}/diff
Retrieves the diff of a commit in a project. Diff limits apply. When a commit exceeds the maximum number of files, pagination stops and no files beyond the limit are returned.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA or name of a repository branch or tag |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
unidiffQuery | Boolean | If true,Default: false |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | Not found | — |
List all merge requests associated with a commit
GET /api/v4/projects/{id}/repository/commits/{sha}/merge_requests
Lists all merge requests associated with a specified commit.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA or name of a repository branch or tag |
stateQuery | String | Filter merge requests by state:opened,closed,locked,merged.Example: merged |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | Not found | — |
List all references a commit is pushed to
GET /api/v4/projects/{id}/repository/commits/{sha}/refs
Lists all references (from branches or tags) a commit is pushed to. The pagination parameters page and per_page can be used to restrict the list of references.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA |
typeQuery | String | Type of references to return for the commit Allowed values: branch,tag,allDefault: all |
pageQuery | Integer | Page number of results to retrieve Default: 1Example: 1 |
per_Query | Integer | Number of items to list per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | Array of APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Revert a commit
POST /api/v4/projects/{id}/repository/commits/{sha}/revert
Reverts a commit in a specified branch. If the revert fails, the 400 response contains a message and an error_code. The error_code is conflict when the revert causes a merge conflict, or empty when the revert changes nothing on the branch, for example because the changes were already reverted or were never on the branch. If dry_run is true, a successful check returns {"dry_run": "success"}, and a failed check returns the same error response with "dry_run": "error" added.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA to revert |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
branchRequired | String | Name of the target branch Example: master |
dry_ | Boolean | If true,Default: false |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad request | — |
404 | Not found | — |
Retrieve a commit sequence
GET /api/v4/projects/{id}/repository/commits/{sha}/sequence
Retrieves the sequence number of a specified commit, found by following the parent links from the commit. The result is the same as git rev-list --count for the commit SHA.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA |
first_Query | Boolean | If true,Default: false |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Retrieve a commit signature
GET /api/v4/projects/{id}/repository/commits/{sha}/signature
Retrieves the signature from a commit, if it is signed. For unsigned commits, it results in a 404 response.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | ID or URL- |
shaPath, | String | Commit SHA or name of a repository branch or tag |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
404 | Not found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesBasicRef
| Property | Type | Description |
|---|---|---|
name | String | Name of the branch or tag Example: v1. |
type | String | Type of the reference.branch or tagExample: tag |
APIEntitiesCommit
| Property | Type | Description |
|---|---|---|
author_ | String | Email address of the commit author Example: john@example. |
author_ | String | Name of the commit author Example: John Smith |
authored_ | String (date- | Date and time when the commit was authored Example: 2012- |
committed_ | String (date- | Date and time when the commit was committed Example: 2012- |
committer_ | String | Email address of the committer Example: jack@example. |
committer_ | String | Name of the committer Example: Jack Smith |
created_ | String (date- | Date and time when the commit was created.committed_Example: 2017- |
extended_ | Object | Git trailers parsed from the commit message, Example: {"Signed- |
id | String | Full SHA of the commit Example: 2695effb5807a22ff3d1 |
message | String | Full commit message Example: Initial commit |
parent_ | Array of strings | SHAs of the parent commits Example: ["2a4b78934375d7f53875 |
short_ | String | Short SHA of the commit Example: 2695effb |
title | String | Title of the commit message Example: Initial commit |
trailers | Object | Git trailers parsed from the commit message. Example: {"Merged- |
web_ | String | URL to view the commit in the Git Example: https: |
APIEntitiesCommitDetail
| Property | Type | Description |
|---|---|---|
author_ | String | Email address of the commit author Example: john@example. |
author_ | String | Name of the commit author Example: John Smith |
authored_ | String (date- | Date and time when the commit was authored Example: 2012- |
committed_ | String (date- | Date and time when the commit was committed Example: 2012- |
committer_ | String | Email address of the committer Example: jack@example. |
committer_ | String | Name of the committer Example: Jack Smith |
created_ | String (date- | Date and time when the commit was created.committed_Example: 2017- |
extended_ | Object | Git trailers parsed from the commit message, Example: {"Signed- |
id | String | Full SHA of the commit Example: 2695effb5807a22ff3d1 |
last_ | Object | Latest pipeline for the commit |
message | String | Full commit message Example: Initial commit |
parent_ | Array of strings | SHAs of the parent commits Example: ["2a4b78934375d7f53875 |
project_ | Integer (int64) | Example:1 |
short_ | String | Short SHA of the commit Example: 2695effb |
stats | APIEntities | Number of lines added and deleted in the commit,stats is true, |
status | String | Status of the latest pipeline for the commit Example: success |
title | String | Title of the commit message Example: Initial commit |
trailers | Object | Git trailers parsed from the commit message. Example: {"Merged- |
web_ | String | URL to view the commit in the Git Example: https: |
APIEntitiesCommitNote
| Property | Type | Description |
|---|---|---|
author | APIEntities | Author of the comment |
created_ | String (date- | Date and time when the comment was created Example: 2016- |
line | Integer | Line number the comment is on Example: 11 |
line_ | String | Type of the line the comment is on,new or oldExample: new |
note | String | Content of the comment Example: this doc is really nice |
path | String | Path of the file the comment is on, Example: README. |
APIEntitiesCommitSequence
| Property | Type | Description |
|---|---|---|
count | Integer | Sequence number of the commit: Example: 1 |
APIEntitiesCommitSignature
| Property | Type | Description |
|---|---|---|
commit_ | String | Source of the commit.gitalyExample: gitaly |
signature | Object | — |
signature_ | String | Type of the signature:PGP,SSH,X509Example: PGP |
APIEntitiesCommitStats
| Property | Type | Description |
|---|---|---|
additions | Integer | Example:1 |
deletions | Integer | Example:0 |
total | Integer | Example:1 |
APIEntitiesCustomAttribute
| Property | Type | Description |
|---|---|---|
key | String | Example:foo |
value | String | Example:bar |
APIEntitiesDiff
| Property | Type | Description |
|---|---|---|
a_ | String | Old file mode of the file Example: 100755 |
b_ | String | New file mode of the file Example: 100644 |
collapsed | Boolean | If true, |
deleted_ | Boolean | If true, |
diff | String | Diff of the changes made to the file Example: @@ - |
generated_ | Boolean | If true, |
new_ | Boolean | If true, |
new_ | String | New path of the file Example: doc/ |
old_ | String | Old path of the file Example: doc/ |
renamed_ | Boolean | If true, |
too_ | Boolean | If true, |
APIEntitiesIssuableReferences
| Property | Type | Description |
|---|---|---|
full | String | Example:test&6 |
relative | String | Example:&6 |
short | String | Example:&6 |
APIEntitiesIssuableTimeStats
| Property | Type | Description |
|---|---|---|
human_ | String | Example:3h 30m |
human_ | String | Example:1h |
time_ | Integer | Example:12600 |
total_ | Integer | Example:3600 |
APIEntitiesMergeRequestAuthor
| Property | Type | Description |
|---|---|---|
avatar_ | String | Example:/ |
avatar_ | String | URL of the user’s avatar Example: https: |
bot | Boolean | If true,Example: false |
custom_ | Array of APIEntities | — |
id | Integer (int64) | ID of the user Example: 1 |
locked | Boolean | If true, |
name | String | Name of the user.**** if the current user cannot read the bot’s project or groupExample: Administrator |
public_ | String | Public email address of the user Example: john@example. |
state | String | State of the user account.active,blocked,ldap_,blocked_,banned,deactivatedExample: active |
username | String | Username of the user Example: admin |
web_ | String | URL of the user’s profile Example: https: |
APIEntitiesMergeRequestBasic
| Property | Type | Description |
|---|---|---|
allow_ | Boolean | If true, |
allow_ | Boolean | Returned only for merge requests from forks.allow_ instead |
assignee | APIEntities | First user assigned to the merge request.assignees instead |
assignees | Array of APIEntities | Users assigned to the merge request |
author | APIEntities | User who created the merge request |
blocking_ | Boolean | If true,true if the project does not require all threads to be resolved before merge |
closed_ | String (date- | Timestamp of when the merge request was closed Example: 2022- |
closed_ | APIEntities | User who closed the merge request.null if the merge request is not closed |
created_ | String (date- | Example:2022- |
description | String | Example:Repellendus impedit et vel velit dignissimos. |
description_ | String | Description of the merge request rendered as HTML.render_ is true |
detailed_ | String | Detailed merge status of the merge request.approvals_ (approvals are syncing),checking (Git is testing whether a valid merge is possible),ci_ (a CI/ci_ (a CI/commits_ (the source branch must exist and contain commits),conflict (conflicts exist between the source and target branches),discussions_ (all discussions must be resolved before merge),draft_ (the merge request is a draft),jira_ (the title or description must reference a Jira issue),locked_ (LFS files locked by other users must be unlocked before merge),locked_ (paths locked by other users must be unlocked before merging to the default branch),merge_ (blocked by another merge request),merge_ (cannot be merged until after the specified time),mergeable (the branch can merge cleanly into the target branch),need_ (the merge request must be rebased),not_ (approval is required before merge),not_ (the merge request must be open before merge),preparing (the merge request diff is being created),requested_ (reviewers have requested changes),security_ (when security policies are enforced,security_ (all security policies must be satisfied),status_ (all status checks must pass before merge),title_ (the title must match the regular expression set in the project settings),unchecked (Git has not yet tested whether a valid merge is possible)Example: mergeable |
discussion_ | Boolean | If true, |
downvotes | Integer | Number of downvotes for the merge request |
draft | Boolean | If true, |
force_ | Boolean | If true, |
has_ | Boolean | If true,false unless merge_ is cannot_ |
id | Integer (int64) | Example:84 |
iid | Integer | Example:14 |
imported | Boolean | If true, |
imported_ | String | Source of the import,bitbucketExample: bitbucket |
labels | Array of strings | Names of the labels assigned to the merge request,with_ is true,id,name,color,text_,description,description_ and archived instead |
merge_ | String (date- | If set, Example: 2022- |
merge_ | String | SHA of the merge commit.null until the merge request is mergedExample: 1234abcd |
merge_ | String | Status of the merge request.unchecked,checking,can_,cannot_ or cannot_.has_.detailed_ insteadExample: unchecked |
merge_ | APIEntities | User who merged the merge request or set it to auto-null |
merge_ | Boolean | If true, |
merged_ | String (date- | Timestamp of when the merge request was merged Example: 2022- |
merged_ | APIEntities | User who merged the merge request or set it to auto-merge_ instead |
milestone | APIEntities | Milestone assigned to the merge request |
prepared_ | String (date- | Timestamp of when the merge request was prepared. Example: 2022- |
project_ | Integer (int64) | Example:4 |
reference | String | Internal reference of the merge request,references insteadExample: !1 |
references | APIEntities | Internal references of the merge request:short,relative and full.relative matches short.relative matches full |
reviewers | Array of APIEntities | Reviewers of the merge request |
sha | String | SHA of the head commit of the source branch Example: 1234abcd |
should_ | Boolean | If true, |
source_ | String | Name of the source branch |
source_ | Integer (int64) | ID of the source project.target_, |
squash | Boolean | If true,squash_ to take them into account |
squash_ | String | SHA of the squash commit. Example: 1234abcd |
squash_ | Boolean | If true, |
state | String | Example:closed |
target_ | String | Name of the target branch |
target_ | Integer (int64) | ID of the target project |
task_ | APIEntities | Completion status of the task list:count and completed_ |
time_ | APIEntities | Time tracking statistics of the merge request:time_,total_,human_ and human_ |
title | String | Example:Impedit et ut et dolores vero provident ullam est |
title_ | String | Title of the merge request rendered as HTML.render_ is true |
updated_ | String (date- | Example:2022- |
upvotes | Integer | Number of upvotes for the merge request |
user_ | Integer | Number of user comments on the merge request |
web_ | String | Web URL of the merge request Example: https: |
work_ | Boolean | If true,draft instead |
APIEntitiesMilestone
| Property | Type | Description |
|---|---|---|
created_ | String | — |
description | String | — |
due_ | String | — |
expired | Boolean | — |
group_ | String | — |
id | Integer (int64) | — |
iid | Integer (int64) | — |
project_ | Integer (int64) | — |
start_ | String | — |
state | String | — |
title | String | — |
updated_ | String | — |
web_ | String | — |
APIEntitiesTaskCompletionStatus
| Property | Type | Description |
|---|---|---|
completed_ | Integer | Example:3 |
count | Integer | Example:5 |
APIEntitiesUserBasic
| Property | Type | Description |
|---|---|---|
avatar_ | String | Example:/ |
avatar_ | String | URL of the user’s avatar Example: https: |
custom_ | Array of APIEntities | — |
id | Integer (int64) | ID of the user Example: 1 |
locked | Boolean | If true, |
name | String | Name of the user.**** if the current user cannot read the bot’s project or groupExample: Administrator |
public_ | String | Public email address of the user Example: john@example. |
state | String | State of the user account.active,blocked,ldap_,blocked_,banned,deactivatedExample: active |
username | String | Username of the user Example: admin |
web_ | String | URL of the user’s profile Example: https: |