Updated on 2026-01-08 GMT+08:00

Creating a Commit

Description

This API is used to commit multiple files in different directories at a time. If the directory does not exist, the system automatically creates a directory. The forcible overwrite option is supported. When the forcible overwrite flag is set to true, the conflict is ignored and the configuration is forcibly committed.

URI

POST /v2/projects/{repo_id}/repository/commits

Table 1 Path parameters

Parameter

Mandatory

Type

Description

repo_id

Yes

Integer

Repository short ID

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

It can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

branch

Yes

String

Target branch

commit_message

Yes

String

Commit message

start_branch

No

String

Name of the new branch

actions

Yes

Array of CommitAction objects

Commit processing list

author_email

No

String

Committer email address

author_name

No

String

Committer name

stats

No

Boolean

Whether to include commit statistics. The default value is true.

force

No

Boolean

Whether to overwrite the target branch. When the value is true, overwrite the target branch with a new commit based on start_branch.

Table 4 CommitAction

Parameter

Mandatory

Type

Description

action

Yes

String

Operations to be performed: create, delete, move, update, and chmod

file_path

Yes

String

Complete path of the file. For example, lib/class.rb.

previous_path

No

String

Original full path of the file to be moved. For example, lib/class1.rb. This parameter is valid only when the move operation is performed.

content

No

String

File content. This parameter is mandatory for the create and update operations. A move operation that does not specify content retains the existing file content, and any other value of the content overwrites the file content.

encoding

No

String

File encoding: text and base64. The default value is text.

last_commit_id

No

String

Last known commit ID. This parameter is valid only when the update, move, or delete operation is performed.

execute_filemode

No

Boolean

Enable or disable the execution mode of a file. This parameter is valid only when the chmod operation is executed.

Response Parameters

Status code: 200

Table 5 Response body parameters

Parameter

Type

Description

error

Error object

Response error

result

CreateCommitResponseBody object

Difference list

status

String

Response status

Table 6 Error

Parameter

Type

Description

code

String

Error codes

message

String

Error message

Table 7 CreateCommitResponseBody

Parameter

Type

Description

id

String

SHA ID of a commit

short_id

String

Short SHA ID of a commit

title

String

Commit title

author_name

String

Author

author_email

String

Author email

committer_name

String

Committer

committer_email

String

Committer email

created_at

String

Creation time

message

String

Commit message

parent_ids

Array of strings

Parent commit ID

committed_date

String

Commit time

authored_date

String

Author commit time

stats

stats object

Statistics

Table 8 stats

Parameter

Type

Description

additions

Integer

Number of lines added in changes

deletions

Integer

Number of lines deleted in changes

total

Integer

Total number of changed lines

Request Examples

POST https://{endpoint}/v2/projects/859341/repository/commits

{
  "branch" : "master",
  "commit_message" : "some commit message",
  "actions" : [ {
    "action" : "create",
    "file_path" : "test001.txt",
    "content" : "some content"
  } ]
}

Response Examples

Status code: 200

Request succeeded

{
  "result" : {
    "id" : "85a0a9d5c6e43bc9c3e443ac01f789e24eeef02b",
    "title" : "some commit message",
    "message" : "some commit message",
    "short_id" : "85a0a9d5",
    "author_name" : "repo",
    "author_email" : null,
    "committer_name" : "repo",
    "committer_email" : null,
    "created_at" : "2021-09-26T03:44:51.000Z",
    "parent_ids" : [ "5c114bb316dff4d4a046e09a5c44c816f2433140" ],
    "committed_date" : "2021-09-26T03:44:51.000Z",
    "authored_date" : null,
    "stats" : {
      "additions" : 1,
      "deletions" : 0,
      "total" : 1
    }
  },
  "status" : "success"
}

Status Codes

Status Codes

Description

200

Request succeeded

Error Codes

See Error Codes.