curl --header
"PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/commits"
响应示例:
"id": "ed899a2f4b50b4370feeea94676502b42383c746",
"short_id": "ed899a2f4b5",
"title": "Replace sanitize with escape once",
"author_name": "Example User",
"author_email": "user@example.com",
"authored_date": "2021-09-20T11:50:22.001+00:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
"committed_date": "2021-09-20T11:50:22.001+00:00",
"created_at": "2021-09-20T11:50:22.001+00:00",
"message": "Replace sanitize with escape once",
"parent_ids": [
"6104942438c14ec7bd21c6cd5bd995272b3faff6"
"web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
"short_id": "6104942438c",
"title": "Sanitize for network graph",
"author_name": "randx",
"author_email": "user@example.com",
"committer_name": "ExampleName",
"committer_email": "user@example.com",
"created_at": "2021-09-20T09:06:12.201+00:00",
"message": "Sanitize for network graph",
"parent_ids": [
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
"web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
创建包含多个文件和操作的提交
POST /projects/:id/repository/commits
需要提交到的分支。要创建一个新的分支,您需要提供 start_branch 和 start_sha 二者之一,还可额外提供 start_project
commit_message
string
start_branch
string
新创建的分支派生自的分支名称
start_sha
string
从中开始新分支的提交的 SHA
start_project
integer/string
经过身份验证的用户拥有的项目 ID 或经过 URL 编码处理的路径,此项目用被用于建立你的新分支。默认值为 id 的值
actions[]
array
要做批处理操作的提交哈希数组。阅读下文了解更多信息
author_email
string
提交作者的邮箱
author_name
string
提交作者的名称
stats
boolean
包含提交状态。默认为 true
force
boolean
若为 true 则会将目标分支使用基于 start_branch 或 start_sha 的新分支覆盖
string
文件内容,除了 delete、chmod 和 move 外其他操作必填。未指定 content 进行移动操作会保留现有文件内容,而为 content 填写任何其他值都会覆盖文件内容
encoding
string
text 或者 base64。默认值是 text
last_commit_id
string
最后一个已知的文件提交 ID。仅适用于update、move 和 delete 操作
execute_filemode
boolean
若为 true/false 则启用/禁用文件的可执行标志。仅适用于 chmod 操作
PAYLOAD=$(cat << 'JSON'
"branch": "master",
"commit_message": "some commit message",
"actions": [
"action": "create",
"file_path": "foo/bar",
"content": "some content"
"action": "delete",
"file_path": "foo/bar2"
"action": "move",
"file_path": "foo/bar3",
"previous_path": "foo/bar4",
"content": "some content"
"action": "update",
"file_path": "foo/bar5",
"content": "new content"
"action": "chmod",
"file_path": "foo/bar5",
"execute_filemode": true
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" \
--data "$PAYLOAD" "https://gitlab.example.com/api/v4/projects/1/repository/commits"
响应示例:
"id": "ed899a2f4b50b4370feeea94676502b42383c746",
"short_id": "ed899a2f4b5",
"title": "some commit message",
"author_name": "Example User",
"author_email": "user@example.com",
"committer_name": "Example User",
"committer_email": "user@example.com",
"created_at": "2016-09-20T09:26:24.000-07:00",
"message": "some commit message",
"parent_ids": [
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
"committed_date": "2016-09-20T09:26:24.000-07:00",
"authored_date": "2016-09-20T09:26:24.000-07:00",
"stats": {
"additions": 2,
"deletions": 2,
"total": 4
"status": null,
"web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
极狐GitLab 支持表单编码。下面就是一个使用表单编码的例子:
curl --request POST \
--form "branch=master" \
--form "commit_message=some commit message" \
--form "start_branch=master" \
--form "actions[][action]=create" \
--form "actions[][file_path]=foo/bar" \
--form "actions[][content]=</path/to/local.file" \
--form "actions[][action]=delete" \
--form "actions[][file_path]=foo/bar2" \
--form "actions[][action]=move" \
--form "actions[][file_path]=foo/bar3" \
--form "actions[][previous_path]=foo/bar4" \
--form "actions[][content]=</path/to/local1.file" \
--form "actions[][action]=update" \
--form "actions[][file_path]=foo/bar5" \
--form "actions[][content]=</path/to/local2.file" \
--form "actions[][action]=chmod" \
--form "actions[][file_path]=foo/bar5" \
--form "actions[][execute_filemode]=true" \
--header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/projects/1/repository/commits"