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 integerThe ID or URL-encoded path of the project
ref_name
Query
StringThe name of a repository branch or tag, if not given the default branch is used
Example: v1.1.0
since
Query
String (date-time)Only commits after or on this date will be returned
Example: 2021-09-20T11:50:22.001Z
until
Query
String (date-time)Only commits before or on this date will be returned
Example: 2021-09-20T11:50:22.001Z
path
Query
StringThe file path
Example: README.md
follow
Query
BooleanFollow file renames when filtering by path
author
Query
StringSearch commits by commit author
Example: John Smith
all
Query
BooleanEvery commit will be returned
with_stats
Query
BooleanStats about each commit will be added to the response
first_parent
Query
BooleanOnly include the first parent of merges
order
Query
StringList commits in order
Allowed values: default, topo
Default: default
trailers
Query
BooleanParse and include Git trailers for every commit
Default: false
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items 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
200OKAPIEntitiesCommit
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 integerThe ID 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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit sha, or the name of a branch or tag
stats
Query
BooleanInclude commit stats
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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit sha, or the name of a branch or tag to be cherry-picked

Request body (application/json)

PropertyTypeDescription
branch
Required
StringThe name of the branch
Example: master
dry_runBooleanDoes not commit any changes
Default: false
messageStringA custom commit message to use for the picked 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 integerThe ID or URL-encoded path of the project
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
sha
Path, required
StringA commit sha, or the name of a branch or tag

Responses

CodeDescriptionSchema
200OKAPIEntitiesCommitNote
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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit sha, or the name of a branch or tag on which to post a comment

Request body (application/json)

PropertyTypeDescription
line
Required
IntegerThe line number
Example: 11
line_type
Required
StringThe type of the line
Allowed values: new, old
Default: new
Minimum length: 1
note
Required
StringThe text of the comment
Example: Nice code!
pathStringThe file path
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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit sha, or the name of a branch or tag
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20
unidiff
Query
BooleanA diff in a Unified diff format
Default: false

Responses

CodeDescriptionSchema
200OKAPIEntitiesDiff
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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit sha, or the name of a branch or tag on which to find Merge Requests
state
Query
StringFilter merge-requests by state
Example: merged
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesMergeRequestBasic
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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit sha
type
Query
StringScope
Allowed values: branch, tag, all
Default: all
page
Query
IntegerCurrent page number
Default: 1
Example: 1
per_page
Query
IntegerNumber of items per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKAPIEntitiesBasicRef
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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringCommit SHA to revert

Request body (application/json)

PropertyTypeDescription
branch
Required
StringTarget branch name
Example: master
dry_runBooleanDoes 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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit SHA
first_parent
Query
BooleanOnly include the first parent of merges
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 integerThe ID or URL-encoded path of the project
sha
Path, required
StringA commit sha, or the name of a 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

APIEntitiesMergeRequestBasic

PropertyTypeDescription
allow_collaborationBoolean—
allow_maintainer_to_pushBoolean—
assigneeAPIEntitiesUserBasic—
assigneesAPIEntitiesUserBasic—
authorAPIEntitiesUserBasic—
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