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. Default is true. Introduced in GitLab 18.10
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

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

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. 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

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. 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

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. Required if path is provided
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. Diff limits apply. When a commit exceeds the maximum number of files, pagination stops and no files beyond the limit are returned.

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. 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

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 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

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
nameStringName of the branch or tag
Example: v1.1.0
typeStringType of the reference. Either branch or tag
Example: tag

APIEntitiesCommit

PropertyTypeDescription
author_emailStringEmail address of the commit author
Example: john@example.com
author_nameStringName of the commit author
Example: John Smith
authored_dateString (date-time)Date and time when the commit was authored
Example: 2012-05-28T04:42:42-07:00
committed_dateString (date-time)Date and time when the commit was committed
Example: 2012-05-28T04:42:42-07:00
committer_emailStringEmail address of the committer
Example: jack@example.com
committer_nameStringName of the committer
Example: Jack Smith
created_atString (date-time)Date and time when the commit was created. Identical to committed_date
Example: 2017-07-26T11:08:53.000+02:00
extended_trailersObjectGit trailers parsed from the commit message, with every value for each key
Example: {"Signed-off-by":["John Doe \u003cjohndoe@gitlab.com\u003e","Jane Doe \u003cjanedoe@gitlab.com\u003e"]}
idStringFull SHA of the commit
Example: 2695effb5807a22ff3d138d593fd856244e155e7
messageStringFull commit message
Example: Initial commit
parent_idsArray of stringsSHAs of the parent commits
Example: ["2a4b78934375d7f53875269ffd4f45fd83a84ebe"]
short_idStringShort SHA of the commit
Example: 2695effb
titleStringTitle of the commit message
Example: Initial commit
trailersObjectGit trailers parsed from the commit message. Duplicate keys include the last value only
Example: {"Merged-By":"Jane Doe janedoe@gitlab.com"}
web_urlStringURL to view the commit in the GitLab UI
Example: https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746

APIEntitiesCommitDetail

PropertyTypeDescription
author_emailStringEmail address of the commit author
Example: john@example.com
author_nameStringName of the commit author
Example: John Smith
authored_dateString (date-time)Date and time when the commit was authored
Example: 2012-05-28T04:42:42-07:00
committed_dateString (date-time)Date and time when the commit was committed
Example: 2012-05-28T04:42:42-07:00
committer_emailStringEmail address of the committer
Example: jack@example.com
committer_nameStringName of the committer
Example: Jack Smith
created_atString (date-time)Date and time when the commit was created. Identical to committed_date
Example: 2017-07-26T11:08:53.000+02:00
extended_trailersObjectGit trailers parsed from the commit message, with every value for each key
Example: {"Signed-off-by":["John Doe \u003cjohndoe@gitlab.com\u003e","Jane Doe \u003cjanedoe@gitlab.com\u003e"]}
idStringFull SHA of the commit
Example: 2695effb5807a22ff3d138d593fd856244e155e7
last_pipelineObjectLatest pipeline for the commit
messageStringFull commit message
Example: Initial commit
parent_idsArray of stringsSHAs of the parent commits
Example: ["2a4b78934375d7f53875269ffd4f45fd83a84ebe"]
project_idInteger (int64)Example: 1
short_idStringShort SHA of the commit
Example: 2695effb
statsAPIEntitiesCommitStatsNumber of lines added and deleted in the commit, and their total. Returned only when stats is true, which is the default where the endpoint supports it
statusStringStatus of the latest pipeline for the commit
Example: success
titleStringTitle of the commit message
Example: Initial commit
trailersObjectGit trailers parsed from the commit message. Duplicate keys include the last value only
Example: {"Merged-By":"Jane Doe janedoe@gitlab.com"}
web_urlStringURL to view the commit in the GitLab UI
Example: https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746

APIEntitiesCommitNote

PropertyTypeDescription
authorAPIEntitiesUserBasicAuthor of the comment
created_atString (date-time)Date and time when the comment was created
Example: 2016-01-19T09:44:55.600Z
lineIntegerLine number the comment is on
Example: 11
line_typeStringType of the line the comment is on, such as new or old
Example: new
noteStringContent of the comment
Example: this doc is really nice
pathStringPath of the file the comment is on, relative to the repository
Example: README.md

APIEntitiesCommitSequence

PropertyTypeDescription
countIntegerSequence number of the commit: the number of commits in its history, including itself
Example: 1

APIEntitiesCommitSignature

PropertyTypeDescription
commit_sourceStringSource of the commit. Always gitaly
Example: gitaly
signatureObject—
signature_typeStringType of the signature: PGP, SSH, or X509
Example: PGP

APIEntitiesCommitStats

PropertyTypeDescription
additionsIntegerExample: 1
deletionsIntegerExample: 0
totalIntegerExample: 1

APIEntitiesCustomAttribute

PropertyTypeDescription
keyStringExample: foo
valueStringExample: bar

APIEntitiesDiff

PropertyTypeDescription
a_modeStringOld file mode of the file
Example: 100755
b_modeStringNew file mode of the file
Example: 100644
collapsedBooleanIf true, the file diff is excluded but can be fetched on request. Introduced in GitLab 18.4
deleted_fileBooleanIf true, the file was removed
diffStringDiff of the changes made to the file
Example: @@ -71,6 +71,8 @@\n...
generated_fileBooleanIf true, the file is marked as generated
new_fileBooleanIf true, the file was added
new_pathStringNew path of the file
Example: doc/update/5.4-to-6.0.md
old_pathStringOld path of the file
Example: doc/update/5.4-to-6.0.md
renamed_fileBooleanIf true, the file was renamed
too_largeBooleanIf true, the file diff is excluded and cannot be retrieved. Introduced in GitLab 18.4

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_urlStringURL of the user’s avatar
Example: https://gravatar.com/avatar/1
botBooleanIf true, the author is a bot
Example: false
custom_attributesArray of APIEntitiesCustomAttribute—
idInteger (int64)ID of the user
Example: 1
lockedBooleanIf true, the user account is locked, and the user cannot sign in until the lock expires or an administrator unlocks the account
nameStringName of the user. For a bot user, **** if the current user cannot read the bot’s project or group
Example: Administrator
public_emailStringPublic email address of the user
Example: john@example.com
stateStringState of the user account. Possible values: active, blocked, ldap_blocked, blocked_pending_approval, banned, or deactivated
Example: active
usernameStringUsername of the user
Example: admin
web_urlStringURL of the user’s profile
Example: https://gitlab.example.com/root

APIEntitiesMergeRequestBasic

PropertyTypeDescription
allow_collaborationBooleanIf true, the fork allows commits from members who can merge to the target branch. Returned only for merge requests from forks
allow_maintainer_to_pushBooleanReturned only for merge requests from forks. Deprecated. Use allow_collaboration instead
assigneeAPIEntitiesUserBasicFirst user assigned to the merge request. Deprecated. Use assignees instead
assigneesArray of APIEntitiesUserBasicUsers assigned to the merge request
authorAPIEntitiesMergeRequestAuthorUser who created the merge request
blocking_discussions_resolvedBooleanIf true, no unresolved threads block the merge. Always true if the project does not require all threads to be resolved before merge
closed_atString (date-time)Timestamp of when the merge request was closed
Example: 2022-01-31T15:10:45.080Z
closed_byAPIEntitiesUserBasicUser who closed the merge request. null if the merge request is not closed
created_atString (date-time)Example: 2022-08-17T12:46:35.053Z
descriptionStringExample: Repellendus impedit et vel velit dignissimos.
description_htmlStringDescription of the merge request rendered as HTML. Returned only if render_html is true
detailed_merge_statusStringDetailed merge status of the merge request. Accounts for every check that can block a merge. Can be approvals_syncing (approvals are syncing), checking (Git is testing whether a valid merge is possible), ci_must_pass (a CI/CD pipeline must succeed before merge), ci_still_running (a CI/CD pipeline is still running), commits_status (the source branch must exist and contain commits), conflict (conflicts exist between the source and target branches), discussions_not_resolved (all discussions must be resolved before merge), draft_status (the merge request is a draft), jira_association_missing (the title or description must reference a Jira issue), locked_lfs_files (LFS files locked by other users must be unlocked before merge), locked_paths (paths locked by other users must be unlocked before merging to the default branch), merge_request_blocked (blocked by another merge request), merge_time (cannot be merged until after the specified time), mergeable (the branch can merge cleanly into the target branch), need_rebase (the merge request must be rebased), not_approved (approval is required before merge), not_open (the merge request must be open before merge), preparing (the merge request diff is being created), requested_changes (reviewers have requested changes), security_policy_pipeline_check (when security policies are enforced, all pipelines for the latest commit must succeed before merge), security_policy_violations (all security policies must be satisfied), status_checks_must_pass (all status checks must pass before merge), title_regex (the title must match the regular expression set in the project settings), or unchecked (Git has not yet tested whether a valid merge is possible)
Example: mergeable
discussion_lockedBooleanIf true, discussions are locked. Only project members can add, edit or resolve comments in locked discussions
downvotesIntegerNumber of downvotes for the merge request
draftBooleanIf true, the merge request is a draft
force_remove_source_branchBooleanIf true, the source branch is forced to be deleted after merge
has_conflictsBooleanIf true, the merge request has conflicts and cannot merge. false unless merge_status is cannot_be_merged
idInteger (int64)Example: 84
iidIntegerExample: 14
importedBooleanIf true, the merge request was imported
imported_fromStringSource of the import, such as bitbucket
Example: bitbucket
labelsArray of stringsNames of the labels assigned to the merge request, sorted by name. If with_labels_details is true, an array of label objects with id, name, color, text_color, description, description_html and archived instead
merge_afterString (date-time)If set, timestamp after which the merge request can be merged. Introduced in GitLab 17.8
Example: 2022-01-31T15:10:45.080Z
merge_commit_shaStringSHA of the merge commit. null until the merge request is merged
Example: 1234abcd
merge_statusStringStatus of the merge request. Can be unchecked, checking, can_be_merged, cannot_be_merged or cannot_be_merged_recheck. Affects has_conflicts. Deprecated. Use detailed_merge_status instead
Example: unchecked
merge_userAPIEntitiesUserBasicUser who merged the merge request or set it to auto-merge, or null
merge_when_pipeline_succeedsBooleanIf true, the merge request is set to auto-merge
merged_atString (date-time)Timestamp of when the merge request was merged
Example: 2022-01-31T15:10:45.080Z
merged_byAPIEntitiesUserBasicUser who merged the merge request or set it to auto-merge. Deprecated. Use merge_user instead
milestoneAPIEntitiesMilestoneMilestone assigned to the merge request
prepared_atString (date-time)Timestamp of when the merge request was prepared. Set one time, after the diff is created, pipeline creation and the mergeability check are started, Git LFS objects are linked, and notifications are sent. Not updated when more changes are added
Example: 2022-01-31T15:10:45.080Z
project_idInteger (int64)Example: 4
referenceStringInternal reference of the merge request, in short format. Deprecated. Use references instead
Example: !1
referencesAPIEntitiesIssuableReferencesInternal references of the merge request: short, relative and full. When fetched from the project of the merge request, relative matches short. When fetched from a project or group in another namespace, relative matches full
reviewersArray of APIEntitiesUserBasicReviewers of the merge request
shaStringSHA of the head commit of the source branch
Example: 1234abcd
should_remove_source_branchBooleanIf true, the source branch is deleted after merge
source_branchStringName of the source branch
source_project_idInteger (int64)ID of the source project. Equal to target_project_id, unless the merge request comes from a fork
squashBooleanIf true, squash commits when merging. Project squash settings can override this value. Use squash_on_merge to take them into account
squash_commit_shaStringSHA of the squash commit. Empty until the merge request is merged
Example: 1234abcd
squash_on_mergeBooleanIf true, commits are squashed on merge
stateStringExample: closed
target_branchStringName of the target branch
target_project_idInteger (int64)ID of the target project
task_completion_statusAPIEntitiesTaskCompletionStatusCompletion status of the task list: count and completed_count
time_statsAPIEntitiesIssuableTimeStatsTime tracking statistics of the merge request: time_estimate, total_time_spent, human_time_estimate and human_total_time_spent
titleStringExample: Impedit et ut et dolores vero provident ullam est
title_htmlStringTitle of the merge request rendered as HTML. Returned only if render_html is true
updated_atString (date-time)Example: 2022-11-14T17:22:01.470Z
upvotesIntegerNumber of upvotes for the merge request
user_notes_countIntegerNumber of user comments on the merge request
web_urlStringWeb URL of the merge request
Example: https://gitlab.example.com/my-group/my-project/-/merge_requests/1
work_in_progressBooleanIf true, the merge request is a draft. Deprecated. Use draft instead

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_urlStringURL of the user’s avatar
Example: https://gravatar.com/avatar/1
custom_attributesArray of APIEntitiesCustomAttribute—
idInteger (int64)ID of the user
Example: 1
lockedBooleanIf true, the user account is locked, and the user cannot sign in until the lock expires or an administrator unlocks the account
nameStringName of the user. For a bot user, **** if the current user cannot read the bot’s project or group
Example: Administrator
public_emailStringPublic email address of the user
Example: john@example.com
stateStringState of the user account. Possible values: active, blocked, ldap_blocked, blocked_pending_approval, banned, or deactivated
Example: active
usernameStringUsername of the user
Example: admin
web_urlStringURL of the user’s profile
Example: https://gitlab.example.com/root