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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
ref_name
Query
StringName of a repository branch, tag, or revision range. Uses the default branch if not given
Example: v1.1.0
since
Query
String (date-time)Only commits after or on this date are returned
Example: 2021-09-20T11:50:22.001Z
until
Query
String (date-time)Only commits before or on this date are returned
Example: 2021-09-20T11:50:22.001Z
path
Query
StringFile path relative to the repository
Example: README.md
follow
Query
BooleanIf true, follows file renames when filtering commits by path and returns commits for the file even if it was renamed. If false, returns only commits where the file existed at its current path. Used only when path specifies a single file
author
Query
StringFilter commits by commit author
Example: John Smith
all
Query
BooleanIf true, retrieves every commit from the repository and ignores the ref_name parameter
with_stats
Query
BooleanIf true, includes statistics for each commit in the response
first_parent
Query
BooleanIf true, follows only the first parent commit upon seeing a merge commit
order
Query
StringOrder in which to list commits, either reverse chronological or topological
Allowed values: default, topo
Default: default
trailers
Query
BooleanIf true, parses and includes Git trailers for every commit
Default: false
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
pagination
Query
StringSpecify the pagination method
Allowed values: legacy, keyset
Default: legacy
page_token
Query
StringRecord from which to start the keyset pagination

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesCommit
400Bad request—
401Unauthorized—
404Not found—

Create a commit

POST /api/v4/projects/{id}/repository/commits

This feature was introduced in GitLab 8.13

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project

Request body (multipart/form-data)

PropertyTypeDescription
file
Required
String (binary)The commit content to be created (generated by Multipart middleware)

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommitDetail
400Bad request—
401Unauthorized—
403Forbidden—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA or name of a repository branch or tag
stats
Query
BooleanIf true, includes commit statistics in the response
Default: true

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommitDetail
400Bad Request—
404Not found—

Cherry-pick a commit

POST /api/v4/projects/{id}/repository/commits/{sha}/cherry_pick

Cherry-picks a commit to a specified branch.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA, or name of a repository branch or tag, to cherry-pick

Request body (application/json)

PropertyTypeDescription
branch
Required
StringName of the branch
Example: master
dry_runBooleanIf true, does not commit any changes
Default: false
messageStringCustom commit message to use for the new commit
Example: Initial commit

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommit
400Bad request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
sha
Path, required
StringCommit SHA or name of a repository branch or tag

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesCommitNote
400Bad Request—
404Not 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.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA or name of a repository branch or tag

Request body (application/json)

PropertyTypeDescription
line
Required
IntegerLine number where the comment should be placed
Example: 11
line_type
Required
StringLine type
Allowed values: new, old
Default: new
Minimum length: 1
note
Required
StringText of the comment
Example: Nice code!
pathStringFile path relative to the repository
Example: doc/update/5.4-to-6.0.md

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommitNote
400Bad request—
404Not found—

Retrieve a commit diff

GET /api/v4/projects/{id}/repository/commits/{sha}/diff

Retrieves the diff of a commit in a project.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA or name of a repository branch or tag
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
unidiff
Query
BooleanIf true, presents diffs in the unified diff format
Default: false

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesDiff
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA or name of a repository branch or tag
state
Query
StringFilter merge requests by state: opened, closed, locked, or merged. If omitted, merge requests of all states are returned. Introduced in GitLab 18.2
Example: merged
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesMergeRequestBasic
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA
type
Query
StringType of references to return for the commit
Allowed values: branch, tag, all
Default: all
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesBasicRef
400Bad Request—
404Not found—

Revert a commit

POST /api/v4/projects/{id}/repository/commits/{sha}/revert

Reverts a commit in a specified branch.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA to revert

Request body (application/json)

PropertyTypeDescription
branch
Required
StringName of the target branch
Example: master
dry_runBooleanIf true, does not commit any changes
Default: false

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommit
400Bad request—
404Not found—

Retrieve a commit sequence

GET /api/v4/projects/{id}/repository/commits/{sha}/sequence

Retrieves the commit sequence for a specified commit.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA
first_parent
Query
BooleanIf true, follows only the first parent commit upon seeing a merge commit
Default: false

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommitSequence
400Bad Request—
404Not 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

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
sha
Path, required
StringCommit SHA or name of a repository branch or tag

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommitSignature
400Bad Request—
404Not found—

Schemas

Objects returned by the operations above and objects nested in their request bodies.

APIEntitiesBasicRef

PropertyTypeDescription
nameStringExample: v1.1.0
typeStringExample: tag

APIEntitiesCommit

PropertyTypeDescription
author_emailStringExample: john@example.com
author_nameStringExample: John Smith
authored_dateString (date-time)Example: 2012-05-28T04:42:42-07:00
committed_dateString (date-time)Example: 2012-05-28T04:42:42-07:00
committer_emailStringExample: jack@example.com
committer_nameStringExample: Jack Smith
created_atString (date-time)Example: 2017-07-26T11:08:53.000+02:00
extended_trailersObjectExample: {"Signed-off-by":["John Doe \u003cjohndoe@gitlab.com\u003e","Jane Doe \u003cjanedoe@gitlab.com\u003e"]}
idStringExample: 2695effb5807a22ff3d138d593fd856244e155e7
messageStringExample: Initial commit
parent_idsArray of stringsExample: ["2a4b78934375d7f53875269ffd4f45fd83a84ebe"]
short_idStringExample: 2695effb
titleStringExample: Initial commit
trailersObjectExample: {"Merged-By":"Jane Doe janedoe@gitlab.com"}
web_urlStringExample: https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746

APIEntitiesCommitDetail

PropertyTypeDescription
author_emailStringExample: john@example.com
author_nameStringExample: John Smith
authored_dateString (date-time)Example: 2012-05-28T04:42:42-07:00
committed_dateString (date-time)Example: 2012-05-28T04:42:42-07:00
committer_emailStringExample: jack@example.com
committer_nameStringExample: Jack Smith
created_atString (date-time)Example: 2017-07-26T11:08:53.000+02:00
extended_trailersObjectExample: {"Signed-off-by":["John Doe \u003cjohndoe@gitlab.com\u003e","Jane Doe \u003cjanedoe@gitlab.com\u003e"]}
idStringExample: 2695effb5807a22ff3d138d593fd856244e155e7
last_pipelineObject—
messageStringExample: Initial commit
parent_idsArray of stringsExample: ["2a4b78934375d7f53875269ffd4f45fd83a84ebe"]
project_idInteger (int64)Example: 1
short_idStringExample: 2695effb
statsAPIEntitiesCommitStats—
statusStringExample: success
titleStringExample: Initial commit
trailersObjectExample: {"Merged-By":"Jane Doe janedoe@gitlab.com"}
web_urlStringExample: https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746

APIEntitiesCommitNote

PropertyTypeDescription
authorAPIEntitiesUserBasic—
created_atString (date-time)Example: 2016-01-19T09:44:55.600Z
lineIntegerExample: 11
line_typeStringExample: new
noteStringExample: this doc is really nice
pathStringExample: README.md

APIEntitiesCommitSequence

PropertyTypeDescription
countIntegerExample: 1

APIEntitiesCommitSignature

PropertyTypeDescription
commit_sourceStringExample: gitaly
signatureObject—
signature_typeStringExample: PGP

APIEntitiesCommitStats

PropertyTypeDescription
additionsIntegerExample: 1
deletionsIntegerExample: 0
totalIntegerExample: 1

APIEntitiesCustomAttribute

PropertyTypeDescription
keyStringExample: foo
valueStringExample: bar

APIEntitiesDiff

PropertyTypeDescription
a_modeStringExample: 100755
b_modeStringExample: 100644
collapsedBoolean—
deleted_fileBoolean—
diffStringExample: @@ -71,6 +71,8 @@\n...
generated_fileBoolean—
new_fileBoolean—
new_pathStringExample: doc/update/5.4-to-6.0.md
old_pathStringExample: doc/update/5.4-to-6.0.md
renamed_fileBoolean—
too_largeBoolean—

APIEntitiesIssuableReferences

PropertyTypeDescription
fullStringExample: test&6
relativeStringExample: &6
shortStringExample: &6

APIEntitiesIssuableTimeStats

PropertyTypeDescription
human_time_estimateStringExample: 3h 30m
human_total_time_spentStringExample: 1h
time_estimateIntegerExample: 12600
total_time_spentIntegerExample: 3600

APIEntitiesMergeRequestAuthor

PropertyTypeDescription
avatar_pathStringExample: /user/avatar/28/The-Big-Lebowski-400-400.png
avatar_urlStringExample: https://gravatar.com/avatar/1
botBooleanExample: false
custom_attributesArray of APIEntitiesCustomAttribute—
idInteger (int64)Example: 1
lockedBoolean—
nameStringExample: Administrator
public_emailStringExample: john@example.com
stateStringExample: active
usernameStringExample: admin
web_urlStringExample: https://gitlab.example.com/root

APIEntitiesMergeRequestBasic

PropertyTypeDescription
allow_collaborationBoolean—
allow_maintainer_to_pushBoolean—
assigneeAPIEntitiesUserBasic—
assigneesAPIEntitiesUserBasic—
authorAPIEntitiesMergeRequestAuthor—
blocking_discussions_resolvedBoolean—
closed_atString (date-time)Example: 2022-01-31T15:10:45.080Z
closed_byAPIEntitiesUserBasic—
created_atString (date-time)Example: 2022-08-17T12:46:35.053Z
descriptionStringExample: Repellendus impedit et vel velit dignissimos.
description_htmlString—
detailed_merge_statusStringExample: mergeable
discussion_lockedBoolean—
downvotesInteger—
draftBoolean—
force_remove_source_branchBoolean—
has_conflictsBoolean—
idInteger (int64)Example: 84
iidIntegerExample: 14
importedBoolean—
imported_fromStringExample: bitbucket
labelsArray of strings—
merge_afterString (date-time)Example: 2022-01-31T15:10:45.080Z
merge_commit_shaStringExample: 1234abcd
merge_statusStringExample: unchecked
merge_userAPIEntitiesUserBasic—
merge_when_pipeline_succeedsBoolean—
merged_atString (date-time)Example: 2022-01-31T15:10:45.080Z
merged_byAPIEntitiesUserBasic—
milestoneAPIEntitiesMilestone—
prepared_atString (date-time)Example: 2022-01-31T15:10:45.080Z
project_idInteger (int64)Example: 4
referenceStringExample: !1
referencesAPIEntitiesIssuableReferences—
reviewersAPIEntitiesUserBasic—
shaStringExample: 1234abcd
should_remove_source_branchBoolean—
source_branchString—
source_project_idInteger (int64)—
squashBoolean—
squash_commit_shaStringExample: 1234abcd
squash_on_mergeBoolean—
stateStringExample: closed
target_branchString—
target_project_idInteger (int64)—
task_completion_statusAPIEntitiesTaskCompletionStatus—
time_statsAPIEntitiesIssuableTimeStats—
titleStringExample: Impedit et ut et dolores vero provident ullam est
title_htmlString—
updated_atString (date-time)Example: 2022-11-14T17:22:01.470Z
upvotesInteger—
user_notes_countInteger—
web_urlStringExample: https://gitlab.example.com/my-group/my-project/-/merge_requests/1
work_in_progressBoolean—

APIEntitiesMilestone

PropertyTypeDescription
created_atString—
descriptionString—
due_dateString—
expiredBoolean—
group_idString—
idInteger (int64)—
iidInteger (int64)—
project_idInteger (int64)—
start_dateString—
stateString—
titleString—
updated_atString—
web_urlString—

APIEntitiesTaskCompletionStatus

PropertyTypeDescription
completed_countIntegerExample: 3
countIntegerExample: 5

APIEntitiesUserBasic

PropertyTypeDescription
avatar_pathStringExample: /user/avatar/28/The-Big-Lebowski-400-400.png
avatar_urlStringExample: https://gravatar.com/avatar/1
custom_attributesArray of APIEntitiesCustomAttribute—
idInteger (int64)Example: 1
lockedBoolean—
nameStringExample: Administrator
public_emailStringExample: john@example.com
stateStringExample: active
usernameStringExample: admin
web_urlStringExample: https://gitlab.example.com/root