InfoGrab DocsInfoGrab Docs

Commits API

요약

이 API를 사용하여 Git 커밋을 관리합니다. 이 API 응답의 일부 날짜 필드는 중복된 정보이거나 중복된 정보처럼 보일 수 있습니다. 성능상의 이유로 GitLab은 Commits API 응답에서 다음 헤더를 반환하지 않습니다.

이 API를 사용하여 Git 커밋을 관리합니다.

응답#

이 API 응답의 일부 날짜 필드는 중복된 정보이거나 중복된 정보처럼 보일 수 있습니다.

  • created_at 필드는 다른 GitLab API와의 일관성을 위해서만 존재합니다. 이 필드는 항상 committed_date 필드와 동일합니다.
  • committed_date 필드와 authored_date 필드는 서로 다른 소스에서 생성되므로 동일하지 않을 수 있습니다.

페이지네이션 응답 헤더#

성능상의 이유로 GitLab은 Commits API 응답에서 다음 헤더를 반환하지 않습니다.

  • x-total
  • x-total-pages

자세한 내용은 이슈 389582를 참고합니다.

리포지터리 커밋 목록 조회#

히스토리
  • GitLab 18.10에서 follow가 도입되었습니다.

프로젝트의 리포지터리 커밋 목록을 가져옵니다.

GET /projects/:id/repository/commits
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
all boolean No 리포지터리의 모든 커밋을 가져옵니다. true이면 ref_name 파라미터는 무시됩니다.
author string No 커밋 작성자로 커밋을 검색합니다.
first_parent boolean No true이면 머지 커밋을 만났을 때 첫 번째 부모 커밋만 따라갑니다.
follow boolean No true이면 path로 커밋을 필터링할 때 파일 이름 변경을 따라가며, 파일 이름이 변경된 경우에도 해당 파일의 커밋을 반환합니다. false이면 파일이 현재 경로에 존재했던 커밋만 반환합니다. path가 단일 파일을 지정한 경우에만 사용됩니다. 기본값은 true입니다.
order string No 커밋을 정렬하여 나열합니다. 사용 가능한 값: default, topo. 기본값은 default이며, 커밋은 최신순으로 표시됩니다.
path string No 파일 경로.
ref_name string No 리포지터리 브랜치, 태그 또는 리비전 범위의 이름. 지정하지 않으면 기본 브랜치입니다.
since string No ISO 8601 형식 YYYY-MM-DDTHH:MM:SSZ 기준으로 이 날짜 이후 또는 해당 날짜의 커밋만 반환합니다.
trailers boolean No true이면 모든 커밋의 Git 트레일러를 파싱하여 포함합니다.
until string No ISO 8601 형식 YYYY-MM-DDTHH:MM:SSZ 기준으로 이 날짜 이전 또는 해당 날짜의 커밋만 반환합니다.
with_stats boolean No true이면 각 커밋의 통계를 가져옵니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 커밋 작성자의 이메일 주소.
author_name string 커밋 작성자의 이름.
authored_date string 커밋이 작성된 날짜.
committed_date string 커밋이 커밋된 날짜.
committer_email string 커밋 커미터의 이메일 주소.
committer_name string 커밋 커미터의 이름.
created_at string 커밋이 생성된 날짜(committed_date와 동일).
extended_trailers object 모든 값을 포함하는 확장 Git 트레일러.
id string 커밋의 SHA.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string 커밋의 짧은 SHA.
title string 커밋 메시지의 제목.
trailers object 커밋 메시지에서 파싱한 Git 트레일러.
web_url string 커밋의 웹 URL.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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",
    "trailers": {},
    "extended_trailers": {}
  },
  {
    "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\nCc: John Doe <johndoe@gitlab.com>\nCc: Jane Doe <janedoe@gitlab.com>",
    "parent_ids": [
      "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
    ],
    "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746",
    "trailers": {
      "Cc": "Jane Doe <janedoe@gitlab.com>"
    },
    "extended_trailers": {
      "Cc": [
        "John Doe <johndoe@gitlab.com>",
        "Jane Doe <janedoe@gitlab.com>"
      ]
    }
  }
]

커밋 생성#

히스토리
  • GitLab 18.8에서 allow_empty가 도입되었습니다.
  • GitLab 18.7에서 요청 크기 및 속도 제한이 도입되었습니다.

JSON 페이로드를 게시하여 커밋을 생성합니다.

POST /projects/:id/repository/commits
Note

이 엔드포인트는 요청 크기 및 속도 제한의 적용을 받습니다. 기본값인 300 MB 제한보다 큰 요청은 거부됩니다. 20 MB를 초과하는 요청은 30초당 3회로 속도가 제한됩니다.

Attribute Type Required Description
branch string Yes 커밋할 브랜치의 이름. 새 브랜치를 생성하려면 start_branch 또는 start_sha 중 하나를 함께 제공하고, 필요하면 start_project도 제공합니다.
commit_message string Yes 커밋 메시지.
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
actions[] array No 배치로 커밋할 action 해시 배열. 사용 가능한 속성은 다음 표를 참고합니다.
allow_empty boolean No true이면 빈 커밋을 생성합니다. 기본값은 false입니다.
author_email string No 커밋 작성자의 이메일 주소를 지정합니다.
author_name string No 커밋 작성자의 이름을 지정합니다.
force boolean No true이면 start_branch 또는 start_sha를 기반으로 하는 새 커밋으로 branch를 덮어써서 브랜치의 기존 커밋 히스토리를 대체합니다. 기본값은 false입니다. 1
start_branch string No 새 커밋의 부모로 사용할 브랜치의 이름. 이 값과 start_sha를 모두 제공하지 않으면 branch 값이 기본값으로 사용됩니다. start_sha와 함께 사용할 수 없습니다. 1
start_project integer or string No start_branch 또는 start_sha의 소스로 사용할 프로젝트 ID 또는 URL 인코딩된 경로. 기본값은 id 값입니다.
start_sha string No 새 커밋의 부모로 사용할 커밋의 SHA. 40자 전체 SHA 여야 합니다. start_branch와 함께 사용할 수 없습니다. 1
stats boolean No 커밋 통계를 포함합니다. 기본값은 true입니다.

각주:

  1. force가 true이면 다른 부모 커밋을 지정하기 위해 start_branch 또는 start_sha를 제공합니다. 둘 다 제공하지 않으면 start_branch는 branch 값으로 기본 설정되고, 새 커밋은 현재 브랜치 팁을 기반으로 생성됩니다. 이 경우 결과가 일반 커밋과 동일하므로 force는 효과가 없습니다.
Note

action 이 많은 대용량 요청은 크기 제한의 적용을 받을 수 있습니다. 자세한 내용은 커밋 API 제한을 참고합니다.

actions[] Attribute Type Required Description
action string Yes 수행할 action: create, delete, move, update, chmod.
file_path string Yes 파일의 전체 경로. 예: lib/class.rb.
content string No 파일 내용. delete, chmod, move를 제외한 모든 action에 필요합니다. content를 지정하지 않은 move action은 기존 파일 내용을 유지하며, 그 외의 content 값은 파일 내용을 덮어씁니다.
encoding string No text 또는 base64. 기본값은 text입니다.
execute_filemode boolean No true이면 파일의 실행 플래그를 활성화하고, false이면 비활성화합니다. chmod action 에만 적용됩니다.
last_commit_id string No 마지막으로 알려진 파일 커밋 ID. update, move, delete action 에만 적용됩니다.
previous_path string No 이동할 파일의 원래 전체 경로. 예: lib/class1.rb. move action 에만 적용됩니다.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 커밋 작성자의 이메일 주소.
author_name string 커밋 작성자의 이름.
authored_date string 커밋이 작성된 날짜.
committed_date string 커밋이 커밋된 날짜.
committer_email string 커밋 커미터의 이메일 주소.
committer_name string 커밋 커미터의 이름.
created_at string 커밋이 생성된 날짜.
id string 생성된 커밋의 SHA.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string 생성된 커밋의 짧은 SHA.
stats object 커밋 통계(추가, 삭제, 전체).
status string 커밋의 상태.
title string 커밋 메시지의 제목.
web_url string 커밋의 웹 URL.
PAYLOAD=$(cat << 'JSON'
{
  "branch": "main",
  "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
    }
  ]
}
JSON
)
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --data "$PAYLOAD" \
  --url "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은 폼 인코딩을 지원합니다. 다음은 폼 인코딩으로 Commit API를 사용하는 예시입니다.

curl --request POST \
     --form "branch=main" \
     --form "commit_message=some commit message" \
     --form "start_branch=main" \
     --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>" \
     --url "https://gitlab.example.com/api/v4/projects/1/repository/commits"

커밋 조회#

커밋 해시 또는 브랜치·태그 이름으로 지정한 커밋을 조회합니다.

GET /projects/:id/repository/commits/:sha

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.
stats boolean No 커밋 통계를 포함합니다. 기본값은 true입니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 커밋 작성자의 이메일 주소.
author_name string 커밋 작성자의 이름.
authored_date string 커밋이 작성된 날짜.
committed_date string 커밋이 커밋된 날짜.
committer_email string 커밋 커미터의 이메일 주소.
committer_name string 커밋 커미터의 이름.
created_at string 커밋이 생성된 날짜.
id string 커밋의 SHA.
last_pipeline object 이 커밋의 마지막 파이프라인 정보.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string 커밋의 짧은 SHA.
stats object 커밋 통계(추가, 삭제, 전체).
status string 커밋의 상태.
title string 커밋 메시지의 제목.
web_url string 커밋의 웹 URL.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main"

응답 예시:

{
  "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
  "short_id": "6104942438c",
  "title": "Sanitize for network graph",
  "author_name": "randx",
  "author_email": "user@example.com",
  "committer_name": "Dmitriy",
  "committer_email": "user@example.com",
  "created_at": "2021-09-20T09:06:12.300+03:00",
  "message": "Sanitize for network graph",
  "committed_date": "2021-09-20T09:06:12.300+03:00",
  "authored_date": "2021-09-20T09:06:12.420+03:00",
  "parent_ids": [
    "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
  ],
  "last_pipeline": {
    "id": 8,
    "ref": "main",
    "sha": "2dc6aa325a317eda67812f05600bdf0fcdc70ab0",
    "status": "created"
  },
  "stats": {
    "additions": 15,
    "deletions": 10,
    "total": 25
  },
  "status": "running",
  "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/6104942438c14ec7bd21c6cd5bd995272b3faff6"
}

커밋이 푸시된 모든 참조 목록 조회#

히스토리

커밋이 푸시된 모든 참조(브랜치 또는 태그)를 나열합니다. 페이지네이션 파라미터 page와 per_page를 사용하여 참조 목록을 제한할 수 있습니다.

GET /projects/:id/repository/commits/:sha/refs

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시.
type string No 커밋의 범위. 사용 가능한 값은 branch, tag, all입니다. 기본값은 all입니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
name string 브랜치 또는 태그의 이름.
type string 참조의 유형(branch 또는 tag).
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/5937ac0a7beb003549fc5fd26fc247adbce4a52e/refs?type=all"

응답 예시:

[
  {
    "type": "branch",
    "name": "'test'"
  },
  {
    "type": "branch",
    "name": "add-balsamiq-file"
  },
  {
    "type": "branch",
    "name": "wip"
  },
  {
    "type": "tag",
    "name": "v1.1.0"
  }
]

커밋 시퀀스 조회#

지정한 커밋에서 부모 링크를 따라가며 프로젝트 내 커밋의 시퀀스 번호를 가져옵니다.

이 API는 지정한 커밋 SHA에 대해 git rev-list --count 명령과 사실상 동일한 기능을 제공합니다.

GET /projects/:id/repository/commits/:sha/sequence

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시.
first_parent boolean No true이면 머지 커밋을 만났을 때 첫 번째 부모 커밋만 따라갑니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
count integer 커밋의 시퀀스 번호.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/5937ac0a7beb003549fc5fd26fc247adbce4a52e/sequence"

응답 예시:

{
  "count": 632
}

커밋 Cherry-pick#

지정한 브랜치로 커밋을 cherry-pick 합니다.

POST /projects/:id/repository/commits/:sha/cherry_pick

파라미터:

Attribute Type Required Description
branch string Yes 브랜치의 이름.
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시.
dry_run boolean No true이면 어떤 변경 사항도 커밋하지 않습니다. 기본값은 false입니다.
message string No 새 커밋에 사용할 사용자 지정 커밋 메시지.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 원본 커밋 작성자의 이메일 주소.
author_name string 원본 커밋 작성자의 이름.
authored_date string 원본 커밋이 작성된 날짜.
committed_date string cherry-pick 된 커밋이 커밋된 날짜.
committer_email string cherry-pick을 수행한 커미터의 이메일 주소.
committer_name string cherry-pick을 수행한 커미터의 이름.
created_at string cherry-pick 된 커밋이 생성된 날짜.
id string cherry-pick 된 커밋의 SHA.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string cherry-pick 된 커밋의 짧은 SHA.
title string 커밋 메시지의 제목.
web_url string cherry-pick 된 커밋의 웹 URL.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --form "branch=main" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main/cherry_pick"

응답 예시:

{
  "id": "8b090c1b79a14f2bd9e8a738f717824ff53aebad",
  "short_id": "8b090c1b",
  "author_name": "Example User",
  "author_email": "user@example.com",
  "authored_date": "2016-12-12T20:10:39.000+01:00",
  "created_at": "2016-12-12T20:10:39.000+01:00",
  "committer_name": "Administrator",
  "committer_email": "admin@example.com",
  "committed_date": "2016-12-12T20:10:39.000+01:00",
  "title": "Feature added",
  "message": "Feature added\n\nSigned-off-by: Example User <user@example.com>\n",
  "parent_ids": [
    "a738f717824ff53aebad8b090c1b79a14f2bd9e8"
  ],
  "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad"
}

cherry-pick 이 실패하면 응답에 실패 원인에 대한 컨텍스트가 포함됩니다.

{
  "message": "Sorry, we cannot cherry-pick this commit automatically. This commit may already have been cherry-picked, or a more recent commit may have updated some of its content.",
  "error_code": "empty"
}

이 경우 변경 세트가 비어 있어 cherry-pick 이 실패했으며, 이는 해당 커밋이 이미 대상 브랜치에 존재함을 뜻할 가능성이 큽니다. 그 밖에 나올 수 있는 오류 코드는 conflict이며, 이는 머지 충돌이 발생했음을 나타냅니다.

dry_run을 활성화하면 서버는 cherry-pick 적용을 시도하지만 그 결과로 생기는 변경 사항을 실제로 커밋하지는 않습니다. cherry-pick 이 문제없이 적용되면 API는 200 OK로 응답합니다.

{
  "dry_run": "success"
}

실패한 경우에는 dry run 없이 실패했을 때와 동일한 오류가 표시됩니다.

커밋 Revert#

지정한 브랜치에서 커밋을 revert 합니다.

POST /projects/:id/repository/commits/:sha/revert

파라미터:

Attribute Type Required Description
branch string Yes 대상 브랜치의 이름.
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes revert 할 커밋 SHA.
dry_run boolean No true이면 어떤 변경 사항도 커밋하지 않습니다. 기본값은 false입니다.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string revert 커밋 작성자의 이메일 주소.
author_name string revert 커밋 작성자의 이름.
authored_date string revert 커밋이 작성된 날짜.
committed_date string revert 커밋이 커밋된 날짜.
committer_email string revert 커밋 커미터의 이메일 주소.
committer_name string revert 커밋 커미터의 이름.
created_at string revert 커밋이 생성된 날짜.
id string revert 커밋의 SHA.
message string 전체 revert 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string revert 커밋의 짧은 SHA.
title string revert 커밋 메시지의 제목.
web_url string revert 커밋의 웹 URL.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --form "branch=main" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/a738f717824ff53aebad8b090c1b79a14f2bd9e8/revert"

응답 예시:

{
  "id": "8b090c1b79a14f2bd9e8a738f717824ff53aebad",
  "short_id": "8b090c1b",
  "title": "Revert \"Feature added\"",
  "created_at": "2018-11-08T15:55:26.000Z",
  "parent_ids": [
    "a738f717824ff53aebad8b090c1b79a14f2bd9e8"
  ],
  "message": "Revert \"Feature added\"\n\nThis reverts commit a738f717824ff53aebad8b090c1b79a14f2bd9e8",
  "author_name": "Administrator",
  "author_email": "admin@example.com",
  "authored_date": "2018-11-08T15:55:26.000Z",
  "committer_name": "Administrator",
  "committer_email": "admin@example.com",
  "committed_date": "2018-11-08T15:55:26.000Z",
  "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad"
}

revert가 실패하면 응답에 실패 원인에 대한 컨텍스트가 포함됩니다.

{
  "message": "Sorry, we cannot revert this commit automatically. This commit may already have been reverted, or a more recent commit may have updated some of its content.",
  "error_code": "conflict"
}

이 경우 시도한 revert가 머지 충돌을 일으켜 revert가 실패했습니다. 그 밖에 나올 수 있는 오류 코드는 empty이며, 이는 변경 세트가 비어 있음을 뜻합니다. 대개 해당 변경이 이미 revert 되었기 때문입니다.

dry_run을 활성화하면 서버는 revert 적용을 시도하지만 그 결과로 생기는 변경 사항을 실제로 커밋하지는 않습니다. revert가 문제없이 적용되면 API는 200 OK로 응답합니다.

{
  "dry_run": "success"
}

실패한 경우에는 dry run 없이 실패했을 때와 동일한 오류가 표시됩니다.

커밋 diff 조회#

히스토리
  • GitLab 18.4에서 collapsed와 too_large 응답 속성이 도입되었습니다.

프로젝트에서 커밋의 diff를 조회합니다.

GET /projects/:id/repository/commits/:sha/diff

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.
unidiff boolean No true이면 diff를 통합 diff 형식으로 표시합니다. 기본값은 false입니다.
Note

이 엔드포인트는 diff 제한의 적용을 받습니다. 커밋이 설정된 최대 파일 수를 초과하면 페이지네이션이 중단되고 제한을 넘는 파일은 더 이상 반환되지 않습니다. GitLab.com의 제한은 diff 표시 제한을 참고합니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
a_mode string 파일의 이전 파일 모드.
b_mode string 파일의 새 파일 모드.
collapsed boolean 파일 diff가 제외되었으나 요청하면 가져올 수 있습니다.
deleted_file boolean 파일이 삭제되었습니다.
diff string 파일에 적용된 변경 사항의 diff 표현.
new_file boolean 파일이 추가되었습니다.
new_path string 파일의 새 경로.
old_path string 파일의 이전 경로.
renamed_file boolean 파일의 이름이 변경되었습니다.
too_large boolean 파일 diff가 제외되었으며 가져올 수 없습니다.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main/diff"

응답 예시:

[
  {
    "diff": "@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files",
    "collapsed": false,
    "too_large": false,
    "new_path": "doc/update/5.4-to-6.0.md",
    "old_path": "doc/update/5.4-to-6.0.md",
    "a_mode": null,
    "b_mode": "100644",
    "new_file": false,
    "renamed_file": false,
    "deleted_file": false
  }
]

모든 커밋 코멘트 목록 조회#

프로젝트 내 커밋의 모든 코멘트를 나열합니다.

GET /projects/:id/repository/commits/:sha/comments

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
author object 코멘트 작성자에 대한 정보.
note string 코멘트 본문.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main/comments"

응답 예시:

[
  {
    "note": "this code is really nice",
    "author": {
      "id": 11,
      "username": "admin",
      "email": "admin@local.host",
      "name": "Administrator",
      "state": "active",
      "created_at": "2014-03-06T08:17:35.000Z"
    }
  }
]

커밋에 코멘트 게시#

커밋에 코멘트를 생성합니다.

특정 파일의 특정 줄에 코멘트를 게시하려면 전체 커밋 SHA, path, line을 지정하고 line_type을 new로 설정해야 합니다.

다음 중 하나라도 해당하면 코멘트는 마지막 커밋의 끝에 추가됩니다.

  • sha가 커밋이 아닌 브랜치 또는 태그이고 line 또는 path가 유효하지 않은 경우
  • line 번호가 유효하지 않은 경우(존재하지 않음)
  • path가 유효하지 않은 경우(존재하지 않음)

위의 경우에는 응답의 line, line_type, path가 null로 설정됩니다.

머지 리퀘스트에 코멘트를 다는 다른 방법은 notes API 의 머지 리퀘스트 노트 생성, discussions API 의 머지 리퀘스트 diff 에 새 스레드 생성 문서를 참고합니다.

POST /projects/:id/repository/commits/:sha/comments
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
note string Yes 코멘트 본문.
sha string Yes 커밋 SHA 또는 리포지터리 브랜치·태그의 이름.
line integer No 코멘트를 달 줄 번호.
line_type string No 줄 유형. new 또는 old를 인수로 받습니다.
path string No 리포지터리 기준 파일 경로.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author object 코멘트 작성자에 대한 정보.
created_at string 코멘트가 생성된 날짜.
line_type string 코멘트가 달린 줄의 유형.
line integer 코멘트가 달린 줄 번호.
note string 코멘트 본문.
path string 리포지터리 기준 파일 경로.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --form "note=Nice picture\!" \
  --form "path=README.md" \
  --form "line=11" \
  --form "line_type=new" \
  --url "https://gitlab.example.com/api/v4/projects/17/repository/commits/18f3e63d05582537db6d183d9d557be09e1f90c8/comments"

응답 예시:

{
  "author": {
    "web_url": "https://gitlab.example.com/janedoe",
    "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
    "username": "janedoe",
    "state": "active",
    "name": "Jane Doe",
    "id": 28
  },
  "created_at": "2016-01-19T09:44:55.600Z",
  "line_type": "new",
  "path": "README.md",
  "line": 11,
  "note": "Nice picture!"
}

모든 커밋 토론 목록 조회#

프로젝트 내 커밋의 모든 토론을 나열합니다.

GET /projects/:id/repository/commits/:sha/discussions

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
id string 토론의 ID.
individual_note boolean true이면 해당 토론은 개별 노트입니다.
notes array 토론에 속한 노트 배열.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/4604744a1c64de00ff62e1e8a6766919923d2b41/discussions"

응답 예시:

[
  {
    "id": "4604744a1c64de00ff62e1e8a6766919923d2b41",
    "individual_note": true,
    "notes": [
      {
        "id": 334686748,
        "type": null,
        "body": "Nice piece of code!",
        "attachment": null,
        "author": {
          "id": 28,
          "name": "Jane Doe",
          "username": "janedoe",
          "web_url": "https://gitlab.example.com/janedoe",
          "state": "active",
          "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png"
        },
        "created_at": "2020-04-30T18:48:11.432Z",
        "updated_at": "2020-04-30T18:48:11.432Z",
        "system": false,
        "noteable_id": null,
        "noteable_type": "Commit",
        "resolvable": false,
        "confidential": null,
        "noteable_iid": null,
        "commands_changes": {}
      }
    ]
  }
]

커밋 상태#

GitLab에서 사용하는 커밋 상태 API 입니다.

커밋 상태 목록 조회#

히스토리
  • GitLab 17.9에서 pipeline_id, order_by, sort 필드가 도입되었습니다.

프로젝트 내 커밋의 상태를 나열합니다. 페이지네이션 파라미터 page와 per_page를 사용하여 참조 목록을 제한할 수 있습니다.

GET /projects/:id/repository/commits/:sha/statuses
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋의 해시.
all boolean No true이면 최신 상태만이 아니라 모든 상태를 포함합니다. 기본값은 false입니다.
name string No job 이름으로 상태를 필터링합니다. 예를 들면 bundler:audit 입니다.
order_by string No 상태 정렬에 사용할 값. 유효한 값은 id 와 pipeline_id 입니다. 기본값은 id 입니다.
pipeline_id integer No 파이프라인 ID 로 상태를 필터링합니다. 예를 들면 1234 입니다.
ref string No 브랜치 또는 태그의 이름. 기본값은 기본 브랜치입니다.
sort string No 상태를 오름차순 또는 내림차순으로 정렬합니다. 유효한 값은 asc 와 desc 입니다. 기본값은 asc 입니다.
stage string No 빌드 Stage로 상태를 필터링합니다. 예를 들면 test 입니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
allow_failure boolean true이면 해당 상태는 실패를 허용합니다.
author object 상태 작성자에 대한 정보.
created_at string 상태가 생성된 날짜.
description string 상태에 대한 설명.
finished_at string 상태가 완료된 날짜.
id integer 상태의 ID.
name string 상태의 이름.
ref string 커밋의 참조(브랜치 또는 태그).
sha string 커밋의 SHA.
started_at string 상태가 시작된 날짜.
status string 커밋의 상태.
target_url string 상태와 연결된 타깃 URL.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/17/repository/commits/18f3e63d05582537db6d183d9d557be09e1f90c8/statuses"

응답 예시:

[
  ...
  {
    "status": "pending",
    "created_at": "2016-01-19T08:40:25.934Z",
    "started_at": null,
    "name": "bundler:audit",
    "allow_failure": true,
    "author": {
      "username": "janedoe",
      "state": "active",
      "web_url": "https://gitlab.example.com/janedoe",
      "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
      "id": 28,
      "name": "Jane Doe"
    },
    "description": null,
    "sha": "18f3e63d05582537db6d183d9d557be09e1f90c8",
    "target_url": "https://gitlab.example.com/janedoe/gitlab-foss/builds/91",
    "finished_at": null,
    "id": 91,
    "ref": "main"
  },
  {
    "started_at": null,
    "name": "test",
    "allow_failure": false,
    "status": "pending",
    "created_at": "2016-01-19T08:40:25.832Z",
    "target_url": "https://gitlab.example.com/janedoe/gitlab-foss/builds/90",
    "id": 90,
    "finished_at": null,
    "ref": "main",
    "sha": "18f3e63d05582537db6d183d9d557be09e1f90c8",
    "author": {
      "id": 28,
      "name": "Jane Doe",
      "username": "janedoe",
      "web_url": "https://gitlab.example.com/janedoe",
      "state": "active",
      "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png"
    },
    "description": null
  }
  ...
]

커밋 파이프라인 상태 설정#

external stage의 job으로 표현되는 커밋의 상태를 추가하거나 업데이트합니다. 커밋이 머지 리퀘스트와 연결되어 있으면 머지 리퀘스트 소스 브랜치의 커밋을 타깃으로 지정합니다.

커밋 상태를 설정하면 다음과 같이 처리됩니다.

  • 먼저 기존 파이프라인을 검색해 job을 추가합니다.
  • 적합한 파이프라인이 없으면 CI_PIPELINE_SOURCE: external로 새 파이프라인이 생성됩니다.

자세한 내용은 외부 커밋 상태를 참고합니다.

Note

동일한 커밋에 중복 파이프라인이 존재하면 어느 파이프라인이 외부 상태를 받는지 모호할 수 있습니다. 파이프라인은 중복이 생기지 않도록 구성합니다.

파이프라인이 이미 존재하고 단일 파이프라인의 최대 job 수 제한을 초과하는 경우는 다음과 같습니다.

  • pipeline_id를 지정하면 422 오류를 반환합니다: The number of jobs has exceeded the limit.
  • 지정하지 않으면 새 파이프라인이 생성됩니다.

SHA/ref 조합에 대한 업데이트가 이미 진행 중이면 409 오류를 반환합니다. 이 오류가 발생하면 요청을 재시도합니다.

POST /projects/:id/statuses/:sha
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 SHA.
state string Yes 상태값. 다음 중 하나입니다: pending, running, success, failed, canceled, skipped.
coverage float No 전체 코드 커버리지.
description string No 상태에 대한 짧은 설명. 255자 이하여야 합니다.
name or context string No 이 상태를 다른 시스템의 상태와 구분하는 레이블. 기본값은 default 입니다.
pipeline_id integer No 상태를 설정할 파이프라인의 ID. 동일한 SHA에 여러 파이프라인이 있는 경우 사용합니다.
ref string No 상태가 참조하는 ref(브랜치 또는 태그). 255자 이하여야 합니다.
target_url string No 이 상태와 연결할 타깃 URL. 255자 이하여야 합니다.

성공 시 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
allow_failure boolean true 이면 해당 상태는 실패를 허용합니다.
author object 상태 작성자에 대한 정보.
coverage float 코드 커버리지 비율.
created_at string 상태가 생성된 날짜.
description string 상태에 대한 설명.
finished_at string 상태가 완료된 날짜.
id integer 상태의 ID.
name string 상태의 이름.
ref string 커밋의 참조(브랜치 또는 태그).
sha string 커밋의 SHA.
started_at string 상태가 시작된 날짜.
status string 커밋의 상태.
target_url string 상태와 연결된 타깃 URL.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/17/statuses/18f3e63d05582537db6d183d9d557be09e1f90c8?state=success"

응답 예시:

{
  "author": {
    "web_url": "https://gitlab.example.com/janedoe",
    "name": "Jane Doe",
    "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
    "username": "janedoe",
    "state": "active",
    "id": 28
  },
  "name": "default",
  "sha": "18f3e63d05582537db6d183d9d557be09e1f90c8",
  "status": "success",
  "coverage": 100.0,
  "description": null,
  "id": 93,
  "target_url": null,
  "ref": null,
  "started_at": null,
  "created_at": "2016-01-19T09:05:50.355Z",
  "allow_failure": false,
  "finished_at": "2016-01-19T09:05:50.365Z"
}

커밋과 연결된 머지 리퀘스트 목록 조회#

히스토리

특정 커밋을 처음 도입한 머지 리퀘스트에 대한 정보를 반환합니다.

GET /projects/:id/repository/commits/:sha/merge_requests
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 SHA.
state string No 지정한 상태의 머지 리퀘스트를 반환합니다: opened, closed, locked, merged. 이 파라미터를 생략하면 상태와 관계없이 모든 머지 리퀘스트를 가져옵니다.

성공 시 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
assignee object 머지 리퀘스트 담당자에 대한 정보.
author object 머지 리퀘스트 작성자에 대한 정보.
created_at string 머지 리퀘스트가 생성된 날짜.
description string 머지 리퀘스트에 대한 설명.
discussion_locked boolean true 이면 토론이 잠겨 있습니다.
downvotes integer 다운보트 수.
draft boolean true 이면 머지 리퀘스트가 드래프트 상태입니다.
force_remove_source_branch boolean true 이면 소스 브랜치를 강제로 제거합니다.
id integer 머지 리퀘스트의 ID.
iid integer 머지 리퀘스트의 내부 ID.
labels array 머지 리퀘스트와 연결된 레이블.
merge_commit_sha string 머지 커밋의 SHA.
merge_status string 머지 리퀘스트의 머지 상태.
merge_when_pipeline_succeeds boolean true 이면 파이프라인이 성공할 때 머지합니다.
milestone object 머지 리퀘스트와 연결된 마일스톤.
project_id integer 프로젝트의 ID.
sha string 머지 리퀘스트의 SHA.
should_remove_source_branch boolean true 이면 머지 후 소스 브랜치를 제거합니다.
source_branch string 머지 리퀘스트의 소스 브랜치.
source_project_id integer 소스 프로젝트의 ID.
squash_commit_sha string 스쿼시 커밋의 SHA.
state string 머지 리퀘스트의 상태.
target_branch string 머지 리퀘스트의 대상 브랜치.
target_project_id integer 타깃 프로젝트의 ID.
time_stats object 시간 추적 통계.
title string 머지 리퀘스트의 제목.
updated_at string 머지 리퀘스트가 마지막으로 업데이트된 날짜.
upvotes integer 업보트 수.
user_notes_count integer 사용자 노트 수.
web_url string 머지 리퀘스트의 웹 URL.
work_in_progress boolean true 이면 머지 리퀘스트가 진행 중인 작업으로 설정됩니다.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/af5b13261899fb2c0db30abdd0af8b07cb44fdc5/merge_requests?state=opened"

응답 예시:

[
  {
    "id": 45,
    "iid": 1,
    "project_id": 35,
    "title": "Add new file",
    "description": "",
    "state": "opened",
    "created_at": "2018-03-26T17:26:30.916Z",
    "updated_at": "2018-03-26T17:26:30.916Z",
    "target_branch": "main",
    "source_branch": "test-branch",
    "upvotes": 0,
    "downvotes": 0,
    "author": {
      "web_url": "https://gitlab.example.com/janedoe",
      "name": "Jane Doe",
      "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
      "username": "janedoe",
      "state": "active",
      "id": 28
    },
    "assignee": null,
    "source_project_id": 35,
    "target_project_id": 35,
    "labels": [],
    "draft": false,
    "work_in_progress": false,
    "milestone": null,
    "merge_when_pipeline_succeeds": false,
    "merge_status": "can_be_merged",
    "sha": "af5b13261899fb2c0db30abdd0af8b07cb44fdc5",
    "merge_commit_sha": null,
    "squash_commit_sha": null,
    "user_notes_count": 0,
    "discussion_locked": null,
    "should_remove_source_branch": null,
    "force_remove_source_branch": false,
    "web_url": "https://gitlab.example.com/root/test-project/merge_requests/1",
    "time_stats": {
      "time_estimate": 0,
      "total_time_spent": 0,
      "human_time_estimate": null,
      "human_total_time_spent": null
    }
  }
]

커밋 서명 조회#

커밋이 서명되어 있으면 커밋의 서명을 가져옵니다. 서명되지 않은 커밋은 404 응답을 반환합니다.

GET /projects/:id/repository/commits/:sha/signature

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치나 태그의 이름.

성공 시 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
commit_source string 커밋의 소스.
gpg_key_id integer GPG 키의 ID(PGP 서명의 경우).
gpg_key_primary_keyid string GPG 키의 기본 키 ID.
gpg_key_subkey_id string GPG 키의 서브키 ID.
gpg_key_user_email string GPG 키와 연결된 이메일 주소.
gpg_key_user_name string GPG 키와 연결된 사용자 이름.
key object SSH 키 정보(SSH 서명의 경우).
signature_type string 서명 유형(PGP, SSH, X509).
verification_status string 서명의 검증 상태.
x509_certificate object X.509 인증서 정보(X.509 서명의 경우).
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/repository/commits/da738facbc19eb2fc2cef57c49be0e6038570352/signature"

커밋이 GPG로 서명된 경우의 응답 예시:

{
  "signature_type": "PGP",
  "verification_status": "verified",
  "gpg_key_id": 1,
  "gpg_key_primary_keyid": "8254AAB3FBD54AC9",
  "gpg_key_user_name": "John Doe",
  "gpg_key_user_email": "johndoe@example.com",
  "gpg_key_subkey_id": null,
  "commit_source": "gitaly"
}

커밋이 SSH로 서명된 경우의 응답 예시:

{
  "signature_type": "SSH",
  "verification_status": "verified",
  "key": {
    "id": 11,
    "title": "Key",
    "created_at": "2023-05-08T09:12:38.503Z",
    "expires_at": "2024-05-07T00:00:00.000Z",
    "key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILZzYDq6DhLp3aX84DGIV3F6Vf+Ae4yCTTz7RnqMJOlR MyKey)",
    "usage_type": "auth_and_signing"
  },
  "commit_source": "gitaly"
}

커밋이 X.509로 서명된 경우의 응답 예시:

{
  "signature_type": "X509",
  "verification_status": "unverified",
  "x509_certificate": {
    "id": 1,
    "subject": "CN=gitlab@example.org,OU=Example,O=World",
    "subject_key_identifier": "BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC",
    "email": "gitlab@example.org",
    "serial_number": 278969561018901340486471282831158785578,
    "certificate_status": "good",
    "x509_issuer": {
      "id": 1,
      "subject": "CN=PKI,OU=Example,O=World",
      "subject_key_identifier": "AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB",
      "crl_url": "http://example.com/pki.crl"
    }
  },
  "commit_source": "gitaly"
}

커밋이 서명되지 않은 경우의 응답 예시:

{
  "message": "404 GPG Signature Not Found"
}

Commits API

GitLab v19.4
Tier: Free, Premium, Ultimate
Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
원문 보기

요약

이 API를 사용하여 Git 커밋을 관리합니다. 이 API 응답의 일부 날짜 필드는 중복된 정보이거나 중복된 정보처럼 보일 수 있습니다. 성능상의 이유로 GitLab은 Commits API 응답에서 다음 헤더를 반환하지 않습니다.

이 API를 사용하여 Git 커밋을 관리합니다.

응답#

이 API 응답의 일부 날짜 필드는 중복된 정보이거나 중복된 정보처럼 보일 수 있습니다.

  • created_at 필드는 다른 GitLab API와의 일관성을 위해서만 존재합니다. 이 필드는 항상 committed_date 필드와 동일합니다.
  • committed_date 필드와 authored_date 필드는 서로 다른 소스에서 생성되므로 동일하지 않을 수 있습니다.

페이지네이션 응답 헤더#

성능상의 이유로 GitLab은 Commits API 응답에서 다음 헤더를 반환하지 않습니다.

  • x-total
  • x-total-pages

자세한 내용은 이슈 389582를 참고합니다.

리포지터리 커밋 목록 조회#

히스토리
  • GitLab 18.10에서 follow가 도입되었습니다.

프로젝트의 리포지터리 커밋 목록을 가져옵니다.

GET /projects/:id/repository/commits
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
all boolean No 리포지터리의 모든 커밋을 가져옵니다. true이면 ref_name 파라미터는 무시됩니다.
author string No 커밋 작성자로 커밋을 검색합니다.
first_parent boolean No true이면 머지 커밋을 만났을 때 첫 번째 부모 커밋만 따라갑니다.
follow boolean No true이면 path로 커밋을 필터링할 때 파일 이름 변경을 따라가며, 파일 이름이 변경된 경우에도 해당 파일의 커밋을 반환합니다. false이면 파일이 현재 경로에 존재했던 커밋만 반환합니다. path가 단일 파일을 지정한 경우에만 사용됩니다. 기본값은 true입니다.
order string No 커밋을 정렬하여 나열합니다. 사용 가능한 값: default, topo. 기본값은 default이며, 커밋은 최신순으로 표시됩니다.
path string No 파일 경로.
ref_name string No 리포지터리 브랜치, 태그 또는 리비전 범위의 이름. 지정하지 않으면 기본 브랜치입니다.
since string No ISO 8601 형식 YYYY-MM-DDTHH:MM:SSZ 기준으로 이 날짜 이후 또는 해당 날짜의 커밋만 반환합니다.
trailers boolean No true이면 모든 커밋의 Git 트레일러를 파싱하여 포함합니다.
until string No ISO 8601 형식 YYYY-MM-DDTHH:MM:SSZ 기준으로 이 날짜 이전 또는 해당 날짜의 커밋만 반환합니다.
with_stats boolean No true이면 각 커밋의 통계를 가져옵니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 커밋 작성자의 이메일 주소.
author_name string 커밋 작성자의 이름.
authored_date string 커밋이 작성된 날짜.
committed_date string 커밋이 커밋된 날짜.
committer_email string 커밋 커미터의 이메일 주소.
committer_name string 커밋 커미터의 이름.
created_at string 커밋이 생성된 날짜(committed_date와 동일).
extended_trailers object 모든 값을 포함하는 확장 Git 트레일러.
id string 커밋의 SHA.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string 커밋의 짧은 SHA.
title string 커밋 메시지의 제목.
trailers object 커밋 메시지에서 파싱한 Git 트레일러.
web_url string 커밋의 웹 URL.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "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",
    "trailers": {},
    "extended_trailers": {}
  },
  {
    "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\nCc: John Doe <johndoe@gitlab.com>\nCc: Jane Doe <janedoe@gitlab.com>",
    "parent_ids": [
      "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
    ],
    "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746",
    "trailers": {
      "Cc": "Jane Doe <janedoe@gitlab.com>"
    },
    "extended_trailers": {
      "Cc": [
        "John Doe <johndoe@gitlab.com>",
        "Jane Doe <janedoe@gitlab.com>"
      ]
    }
  }
]

커밋 생성#

히스토리
  • GitLab 18.8에서 allow_empty가 도입되었습니다.
  • GitLab 18.7에서 요청 크기 및 속도 제한이 도입되었습니다.

JSON 페이로드를 게시하여 커밋을 생성합니다.

POST /projects/:id/repository/commits
Note

이 엔드포인트는 요청 크기 및 속도 제한의 적용을 받습니다. 기본값인 300 MB 제한보다 큰 요청은 거부됩니다. 20 MB를 초과하는 요청은 30초당 3회로 속도가 제한됩니다.

Attribute Type Required Description
branch string Yes 커밋할 브랜치의 이름. 새 브랜치를 생성하려면 start_branch 또는 start_sha 중 하나를 함께 제공하고, 필요하면 start_project도 제공합니다.
commit_message string Yes 커밋 메시지.
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
actions[] array No 배치로 커밋할 action 해시 배열. 사용 가능한 속성은 다음 표를 참고합니다.
allow_empty boolean No true이면 빈 커밋을 생성합니다. 기본값은 false입니다.
author_email string No 커밋 작성자의 이메일 주소를 지정합니다.
author_name string No 커밋 작성자의 이름을 지정합니다.
force boolean No true이면 start_branch 또는 start_sha를 기반으로 하는 새 커밋으로 branch를 덮어써서 브랜치의 기존 커밋 히스토리를 대체합니다. 기본값은 false입니다. 1
start_branch string No 새 커밋의 부모로 사용할 브랜치의 이름. 이 값과 start_sha를 모두 제공하지 않으면 branch 값이 기본값으로 사용됩니다. start_sha와 함께 사용할 수 없습니다. 1
start_project integer or string No start_branch 또는 start_sha의 소스로 사용할 프로젝트 ID 또는 URL 인코딩된 경로. 기본값은 id 값입니다.
start_sha string No 새 커밋의 부모로 사용할 커밋의 SHA. 40자 전체 SHA 여야 합니다. start_branch와 함께 사용할 수 없습니다. 1
stats boolean No 커밋 통계를 포함합니다. 기본값은 true입니다.

각주:

  1. force가 true이면 다른 부모 커밋을 지정하기 위해 start_branch 또는 start_sha를 제공합니다. 둘 다 제공하지 않으면 start_branch는 branch 값으로 기본 설정되고, 새 커밋은 현재 브랜치 팁을 기반으로 생성됩니다. 이 경우 결과가 일반 커밋과 동일하므로 force는 효과가 없습니다.
Note

action 이 많은 대용량 요청은 크기 제한의 적용을 받을 수 있습니다. 자세한 내용은 커밋 API 제한을 참고합니다.

actions[] Attribute Type Required Description
action string Yes 수행할 action: create, delete, move, update, chmod.
file_path string Yes 파일의 전체 경로. 예: lib/class.rb.
content string No 파일 내용. delete, chmod, move를 제외한 모든 action에 필요합니다. content를 지정하지 않은 move action은 기존 파일 내용을 유지하며, 그 외의 content 값은 파일 내용을 덮어씁니다.
encoding string No text 또는 base64. 기본값은 text입니다.
execute_filemode boolean No true이면 파일의 실행 플래그를 활성화하고, false이면 비활성화합니다. chmod action 에만 적용됩니다.
last_commit_id string No 마지막으로 알려진 파일 커밋 ID. update, move, delete action 에만 적용됩니다.
previous_path string No 이동할 파일의 원래 전체 경로. 예: lib/class1.rb. move action 에만 적용됩니다.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 커밋 작성자의 이메일 주소.
author_name string 커밋 작성자의 이름.
authored_date string 커밋이 작성된 날짜.
committed_date string 커밋이 커밋된 날짜.
committer_email string 커밋 커미터의 이메일 주소.
committer_name string 커밋 커미터의 이름.
created_at string 커밋이 생성된 날짜.
id string 생성된 커밋의 SHA.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string 생성된 커밋의 짧은 SHA.
stats object 커밋 통계(추가, 삭제, 전체).
status string 커밋의 상태.
title string 커밋 메시지의 제목.
web_url string 커밋의 웹 URL.
PAYLOAD=$(cat << 'JSON'
{
  "branch": "main",
  "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
    }
  ]
}
JSON
)
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --header "Content-Type: application/json" \
  --data "$PAYLOAD" \
  --url "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은 폼 인코딩을 지원합니다. 다음은 폼 인코딩으로 Commit API를 사용하는 예시입니다.

curl --request POST \
     --form "branch=main" \
     --form "commit_message=some commit message" \
     --form "start_branch=main" \
     --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>" \
     --url "https://gitlab.example.com/api/v4/projects/1/repository/commits"

커밋 조회#

커밋 해시 또는 브랜치·태그 이름으로 지정한 커밋을 조회합니다.

GET /projects/:id/repository/commits/:sha

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.
stats boolean No 커밋 통계를 포함합니다. 기본값은 true입니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 커밋 작성자의 이메일 주소.
author_name string 커밋 작성자의 이름.
authored_date string 커밋이 작성된 날짜.
committed_date string 커밋이 커밋된 날짜.
committer_email string 커밋 커미터의 이메일 주소.
committer_name string 커밋 커미터의 이름.
created_at string 커밋이 생성된 날짜.
id string 커밋의 SHA.
last_pipeline object 이 커밋의 마지막 파이프라인 정보.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string 커밋의 짧은 SHA.
stats object 커밋 통계(추가, 삭제, 전체).
status string 커밋의 상태.
title string 커밋 메시지의 제목.
web_url string 커밋의 웹 URL.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main"

응답 예시:

{
  "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
  "short_id": "6104942438c",
  "title": "Sanitize for network graph",
  "author_name": "randx",
  "author_email": "user@example.com",
  "committer_name": "Dmitriy",
  "committer_email": "user@example.com",
  "created_at": "2021-09-20T09:06:12.300+03:00",
  "message": "Sanitize for network graph",
  "committed_date": "2021-09-20T09:06:12.300+03:00",
  "authored_date": "2021-09-20T09:06:12.420+03:00",
  "parent_ids": [
    "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
  ],
  "last_pipeline": {
    "id": 8,
    "ref": "main",
    "sha": "2dc6aa325a317eda67812f05600bdf0fcdc70ab0",
    "status": "created"
  },
  "stats": {
    "additions": 15,
    "deletions": 10,
    "total": 25
  },
  "status": "running",
  "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/6104942438c14ec7bd21c6cd5bd995272b3faff6"
}

커밋이 푸시된 모든 참조 목록 조회#

히스토리

커밋이 푸시된 모든 참조(브랜치 또는 태그)를 나열합니다. 페이지네이션 파라미터 page와 per_page를 사용하여 참조 목록을 제한할 수 있습니다.

GET /projects/:id/repository/commits/:sha/refs

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시.
type string No 커밋의 범위. 사용 가능한 값은 branch, tag, all입니다. 기본값은 all입니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
name string 브랜치 또는 태그의 이름.
type string 참조의 유형(branch 또는 tag).
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/5937ac0a7beb003549fc5fd26fc247adbce4a52e/refs?type=all"

응답 예시:

[
  {
    "type": "branch",
    "name": "'test'"
  },
  {
    "type": "branch",
    "name": "add-balsamiq-file"
  },
  {
    "type": "branch",
    "name": "wip"
  },
  {
    "type": "tag",
    "name": "v1.1.0"
  }
]

커밋 시퀀스 조회#

지정한 커밋에서 부모 링크를 따라가며 프로젝트 내 커밋의 시퀀스 번호를 가져옵니다.

이 API는 지정한 커밋 SHA에 대해 git rev-list --count 명령과 사실상 동일한 기능을 제공합니다.

GET /projects/:id/repository/commits/:sha/sequence

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시.
first_parent boolean No true이면 머지 커밋을 만났을 때 첫 번째 부모 커밋만 따라갑니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
count integer 커밋의 시퀀스 번호.

요청 예시:

curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/5937ac0a7beb003549fc5fd26fc247adbce4a52e/sequence"

응답 예시:

{
  "count": 632
}

커밋 Cherry-pick#

지정한 브랜치로 커밋을 cherry-pick 합니다.

POST /projects/:id/repository/commits/:sha/cherry_pick

파라미터:

Attribute Type Required Description
branch string Yes 브랜치의 이름.
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시.
dry_run boolean No true이면 어떤 변경 사항도 커밋하지 않습니다. 기본값은 false입니다.
message string No 새 커밋에 사용할 사용자 지정 커밋 메시지.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string 원본 커밋 작성자의 이메일 주소.
author_name string 원본 커밋 작성자의 이름.
authored_date string 원본 커밋이 작성된 날짜.
committed_date string cherry-pick 된 커밋이 커밋된 날짜.
committer_email string cherry-pick을 수행한 커미터의 이메일 주소.
committer_name string cherry-pick을 수행한 커미터의 이름.
created_at string cherry-pick 된 커밋이 생성된 날짜.
id string cherry-pick 된 커밋의 SHA.
message string 전체 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string cherry-pick 된 커밋의 짧은 SHA.
title string 커밋 메시지의 제목.
web_url string cherry-pick 된 커밋의 웹 URL.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --form "branch=main" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main/cherry_pick"

응답 예시:

{
  "id": "8b090c1b79a14f2bd9e8a738f717824ff53aebad",
  "short_id": "8b090c1b",
  "author_name": "Example User",
  "author_email": "user@example.com",
  "authored_date": "2016-12-12T20:10:39.000+01:00",
  "created_at": "2016-12-12T20:10:39.000+01:00",
  "committer_name": "Administrator",
  "committer_email": "admin@example.com",
  "committed_date": "2016-12-12T20:10:39.000+01:00",
  "title": "Feature added",
  "message": "Feature added\n\nSigned-off-by: Example User <user@example.com>\n",
  "parent_ids": [
    "a738f717824ff53aebad8b090c1b79a14f2bd9e8"
  ],
  "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad"
}

cherry-pick 이 실패하면 응답에 실패 원인에 대한 컨텍스트가 포함됩니다.

{
  "message": "Sorry, we cannot cherry-pick this commit automatically. This commit may already have been cherry-picked, or a more recent commit may have updated some of its content.",
  "error_code": "empty"
}

이 경우 변경 세트가 비어 있어 cherry-pick 이 실패했으며, 이는 해당 커밋이 이미 대상 브랜치에 존재함을 뜻할 가능성이 큽니다. 그 밖에 나올 수 있는 오류 코드는 conflict이며, 이는 머지 충돌이 발생했음을 나타냅니다.

dry_run을 활성화하면 서버는 cherry-pick 적용을 시도하지만 그 결과로 생기는 변경 사항을 실제로 커밋하지는 않습니다. cherry-pick 이 문제없이 적용되면 API는 200 OK로 응답합니다.

{
  "dry_run": "success"
}

실패한 경우에는 dry run 없이 실패했을 때와 동일한 오류가 표시됩니다.

커밋 Revert#

지정한 브랜치에서 커밋을 revert 합니다.

POST /projects/:id/repository/commits/:sha/revert

파라미터:

Attribute Type Required Description
branch string Yes 대상 브랜치의 이름.
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes revert 할 커밋 SHA.
dry_run boolean No true이면 어떤 변경 사항도 커밋하지 않습니다. 기본값은 false입니다.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author_email string revert 커밋 작성자의 이메일 주소.
author_name string revert 커밋 작성자의 이름.
authored_date string revert 커밋이 작성된 날짜.
committed_date string revert 커밋이 커밋된 날짜.
committer_email string revert 커밋 커미터의 이메일 주소.
committer_name string revert 커밋 커미터의 이름.
created_at string revert 커밋이 생성된 날짜.
id string revert 커밋의 SHA.
message string 전체 revert 커밋 메시지.
parent_ids array 부모 커밋 SHA 배열.
short_id string revert 커밋의 짧은 SHA.
title string revert 커밋 메시지의 제목.
web_url string revert 커밋의 웹 URL.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --form "branch=main" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/a738f717824ff53aebad8b090c1b79a14f2bd9e8/revert"

응답 예시:

{
  "id": "8b090c1b79a14f2bd9e8a738f717824ff53aebad",
  "short_id": "8b090c1b",
  "title": "Revert \"Feature added\"",
  "created_at": "2018-11-08T15:55:26.000Z",
  "parent_ids": [
    "a738f717824ff53aebad8b090c1b79a14f2bd9e8"
  ],
  "message": "Revert \"Feature added\"\n\nThis reverts commit a738f717824ff53aebad8b090c1b79a14f2bd9e8",
  "author_name": "Administrator",
  "author_email": "admin@example.com",
  "authored_date": "2018-11-08T15:55:26.000Z",
  "committer_name": "Administrator",
  "committer_email": "admin@example.com",
  "committed_date": "2018-11-08T15:55:26.000Z",
  "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/8b090c1b79a14f2bd9e8a738f717824ff53aebad"
}

revert가 실패하면 응답에 실패 원인에 대한 컨텍스트가 포함됩니다.

{
  "message": "Sorry, we cannot revert this commit automatically. This commit may already have been reverted, or a more recent commit may have updated some of its content.",
  "error_code": "conflict"
}

이 경우 시도한 revert가 머지 충돌을 일으켜 revert가 실패했습니다. 그 밖에 나올 수 있는 오류 코드는 empty이며, 이는 변경 세트가 비어 있음을 뜻합니다. 대개 해당 변경이 이미 revert 되었기 때문입니다.

dry_run을 활성화하면 서버는 revert 적용을 시도하지만 그 결과로 생기는 변경 사항을 실제로 커밋하지는 않습니다. revert가 문제없이 적용되면 API는 200 OK로 응답합니다.

{
  "dry_run": "success"
}

실패한 경우에는 dry run 없이 실패했을 때와 동일한 오류가 표시됩니다.

커밋 diff 조회#

히스토리
  • GitLab 18.4에서 collapsed와 too_large 응답 속성이 도입되었습니다.

프로젝트에서 커밋의 diff를 조회합니다.

GET /projects/:id/repository/commits/:sha/diff

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.
unidiff boolean No true이면 diff를 통합 diff 형식으로 표시합니다. 기본값은 false입니다.
Note

이 엔드포인트는 diff 제한의 적용을 받습니다. 커밋이 설정된 최대 파일 수를 초과하면 페이지네이션이 중단되고 제한을 넘는 파일은 더 이상 반환되지 않습니다. GitLab.com의 제한은 diff 표시 제한을 참고합니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
a_mode string 파일의 이전 파일 모드.
b_mode string 파일의 새 파일 모드.
collapsed boolean 파일 diff가 제외되었으나 요청하면 가져올 수 있습니다.
deleted_file boolean 파일이 삭제되었습니다.
diff string 파일에 적용된 변경 사항의 diff 표현.
new_file boolean 파일이 추가되었습니다.
new_path string 파일의 새 경로.
old_path string 파일의 이전 경로.
renamed_file boolean 파일의 이름이 변경되었습니다.
too_large boolean 파일 diff가 제외되었으며 가져올 수 없습니다.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main/diff"

응답 예시:

[
  {
    "diff": "@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files",
    "collapsed": false,
    "too_large": false,
    "new_path": "doc/update/5.4-to-6.0.md",
    "old_path": "doc/update/5.4-to-6.0.md",
    "a_mode": null,
    "b_mode": "100644",
    "new_file": false,
    "renamed_file": false,
    "deleted_file": false
  }
]

모든 커밋 코멘트 목록 조회#

프로젝트 내 커밋의 모든 코멘트를 나열합니다.

GET /projects/:id/repository/commits/:sha/comments

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
author object 코멘트 작성자에 대한 정보.
note string 코멘트 본문.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/main/comments"

응답 예시:

[
  {
    "note": "this code is really nice",
    "author": {
      "id": 11,
      "username": "admin",
      "email": "admin@local.host",
      "name": "Administrator",
      "state": "active",
      "created_at": "2014-03-06T08:17:35.000Z"
    }
  }
]

커밋에 코멘트 게시#

커밋에 코멘트를 생성합니다.

특정 파일의 특정 줄에 코멘트를 게시하려면 전체 커밋 SHA, path, line을 지정하고 line_type을 new로 설정해야 합니다.

다음 중 하나라도 해당하면 코멘트는 마지막 커밋의 끝에 추가됩니다.

  • sha가 커밋이 아닌 브랜치 또는 태그이고 line 또는 path가 유효하지 않은 경우
  • line 번호가 유효하지 않은 경우(존재하지 않음)
  • path가 유효하지 않은 경우(존재하지 않음)

위의 경우에는 응답의 line, line_type, path가 null로 설정됩니다.

머지 리퀘스트에 코멘트를 다는 다른 방법은 notes API 의 머지 리퀘스트 노트 생성, discussions API 의 머지 리퀘스트 diff 에 새 스레드 생성 문서를 참고합니다.

POST /projects/:id/repository/commits/:sha/comments
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
note string Yes 코멘트 본문.
sha string Yes 커밋 SHA 또는 리포지터리 브랜치·태그의 이름.
line integer No 코멘트를 달 줄 번호.
line_type string No 줄 유형. new 또는 old를 인수로 받습니다.
path string No 리포지터리 기준 파일 경로.

성공하면 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
author object 코멘트 작성자에 대한 정보.
created_at string 코멘트가 생성된 날짜.
line_type string 코멘트가 달린 줄의 유형.
line integer 코멘트가 달린 줄 번호.
note string 코멘트 본문.
path string 리포지터리 기준 파일 경로.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --form "note=Nice picture\!" \
  --form "path=README.md" \
  --form "line=11" \
  --form "line_type=new" \
  --url "https://gitlab.example.com/api/v4/projects/17/repository/commits/18f3e63d05582537db6d183d9d557be09e1f90c8/comments"

응답 예시:

{
  "author": {
    "web_url": "https://gitlab.example.com/janedoe",
    "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
    "username": "janedoe",
    "state": "active",
    "name": "Jane Doe",
    "id": 28
  },
  "created_at": "2016-01-19T09:44:55.600Z",
  "line_type": "new",
  "path": "README.md",
  "line": 11,
  "note": "Nice picture!"
}

모든 커밋 토론 목록 조회#

프로젝트 내 커밋의 모든 토론을 나열합니다.

GET /projects/:id/repository/commits/:sha/discussions

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치·태그의 이름.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
id string 토론의 ID.
individual_note boolean true이면 해당 토론은 개별 노트입니다.
notes array 토론에 속한 노트 배열.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/4604744a1c64de00ff62e1e8a6766919923d2b41/discussions"

응답 예시:

[
  {
    "id": "4604744a1c64de00ff62e1e8a6766919923d2b41",
    "individual_note": true,
    "notes": [
      {
        "id": 334686748,
        "type": null,
        "body": "Nice piece of code!",
        "attachment": null,
        "author": {
          "id": 28,
          "name": "Jane Doe",
          "username": "janedoe",
          "web_url": "https://gitlab.example.com/janedoe",
          "state": "active",
          "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png"
        },
        "created_at": "2020-04-30T18:48:11.432Z",
        "updated_at": "2020-04-30T18:48:11.432Z",
        "system": false,
        "noteable_id": null,
        "noteable_type": "Commit",
        "resolvable": false,
        "confidential": null,
        "noteable_iid": null,
        "commands_changes": {}
      }
    ]
  }
]

커밋 상태#

GitLab에서 사용하는 커밋 상태 API 입니다.

커밋 상태 목록 조회#

히스토리
  • GitLab 17.9에서 pipeline_id, order_by, sort 필드가 도입되었습니다.

프로젝트 내 커밋의 상태를 나열합니다. 페이지네이션 파라미터 page와 per_page를 사용하여 참조 목록을 제한할 수 있습니다.

GET /projects/:id/repository/commits/:sha/statuses
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋의 해시.
all boolean No true이면 최신 상태만이 아니라 모든 상태를 포함합니다. 기본값은 false입니다.
name string No job 이름으로 상태를 필터링합니다. 예를 들면 bundler:audit 입니다.
order_by string No 상태 정렬에 사용할 값. 유효한 값은 id 와 pipeline_id 입니다. 기본값은 id 입니다.
pipeline_id integer No 파이프라인 ID 로 상태를 필터링합니다. 예를 들면 1234 입니다.
ref string No 브랜치 또는 태그의 이름. 기본값은 기본 브랜치입니다.
sort string No 상태를 오름차순 또는 내림차순으로 정렬합니다. 유효한 값은 asc 와 desc 입니다. 기본값은 asc 입니다.
stage string No 빌드 Stage로 상태를 필터링합니다. 예를 들면 test 입니다.

성공하면 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
allow_failure boolean true이면 해당 상태는 실패를 허용합니다.
author object 상태 작성자에 대한 정보.
created_at string 상태가 생성된 날짜.
description string 상태에 대한 설명.
finished_at string 상태가 완료된 날짜.
id integer 상태의 ID.
name string 상태의 이름.
ref string 커밋의 참조(브랜치 또는 태그).
sha string 커밋의 SHA.
started_at string 상태가 시작된 날짜.
status string 커밋의 상태.
target_url string 상태와 연결된 타깃 URL.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/17/repository/commits/18f3e63d05582537db6d183d9d557be09e1f90c8/statuses"

응답 예시:

[
  ...
  {
    "status": "pending",
    "created_at": "2016-01-19T08:40:25.934Z",
    "started_at": null,
    "name": "bundler:audit",
    "allow_failure": true,
    "author": {
      "username": "janedoe",
      "state": "active",
      "web_url": "https://gitlab.example.com/janedoe",
      "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
      "id": 28,
      "name": "Jane Doe"
    },
    "description": null,
    "sha": "18f3e63d05582537db6d183d9d557be09e1f90c8",
    "target_url": "https://gitlab.example.com/janedoe/gitlab-foss/builds/91",
    "finished_at": null,
    "id": 91,
    "ref": "main"
  },
  {
    "started_at": null,
    "name": "test",
    "allow_failure": false,
    "status": "pending",
    "created_at": "2016-01-19T08:40:25.832Z",
    "target_url": "https://gitlab.example.com/janedoe/gitlab-foss/builds/90",
    "id": 90,
    "finished_at": null,
    "ref": "main",
    "sha": "18f3e63d05582537db6d183d9d557be09e1f90c8",
    "author": {
      "id": 28,
      "name": "Jane Doe",
      "username": "janedoe",
      "web_url": "https://gitlab.example.com/janedoe",
      "state": "active",
      "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png"
    },
    "description": null
  }
  ...
]

커밋 파이프라인 상태 설정#

external stage의 job으로 표현되는 커밋의 상태를 추가하거나 업데이트합니다. 커밋이 머지 리퀘스트와 연결되어 있으면 머지 리퀘스트 소스 브랜치의 커밋을 타깃으로 지정합니다.

커밋 상태를 설정하면 다음과 같이 처리됩니다.

  • 먼저 기존 파이프라인을 검색해 job을 추가합니다.
  • 적합한 파이프라인이 없으면 CI_PIPELINE_SOURCE: external로 새 파이프라인이 생성됩니다.

자세한 내용은 외부 커밋 상태를 참고합니다.

Note

동일한 커밋에 중복 파이프라인이 존재하면 어느 파이프라인이 외부 상태를 받는지 모호할 수 있습니다. 파이프라인은 중복이 생기지 않도록 구성합니다.

파이프라인이 이미 존재하고 단일 파이프라인의 최대 job 수 제한을 초과하는 경우는 다음과 같습니다.

  • pipeline_id를 지정하면 422 오류를 반환합니다: The number of jobs has exceeded the limit.
  • 지정하지 않으면 새 파이프라인이 생성됩니다.

SHA/ref 조합에 대한 업데이트가 이미 진행 중이면 409 오류를 반환합니다. 이 오류가 발생하면 요청을 재시도합니다.

POST /projects/:id/statuses/:sha
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 SHA.
state string Yes 상태값. 다음 중 하나입니다: pending, running, success, failed, canceled, skipped.
coverage float No 전체 코드 커버리지.
description string No 상태에 대한 짧은 설명. 255자 이하여야 합니다.
name or context string No 이 상태를 다른 시스템의 상태와 구분하는 레이블. 기본값은 default 입니다.
pipeline_id integer No 상태를 설정할 파이프라인의 ID. 동일한 SHA에 여러 파이프라인이 있는 경우 사용합니다.
ref string No 상태가 참조하는 ref(브랜치 또는 태그). 255자 이하여야 합니다.
target_url string No 이 상태와 연결할 타깃 URL. 255자 이하여야 합니다.

성공 시 201 Created와 다음 응답 속성을 반환합니다.

Attribute Type Description
allow_failure boolean true 이면 해당 상태는 실패를 허용합니다.
author object 상태 작성자에 대한 정보.
coverage float 코드 커버리지 비율.
created_at string 상태가 생성된 날짜.
description string 상태에 대한 설명.
finished_at string 상태가 완료된 날짜.
id integer 상태의 ID.
name string 상태의 이름.
ref string 커밋의 참조(브랜치 또는 태그).
sha string 커밋의 SHA.
started_at string 상태가 시작된 날짜.
status string 커밋의 상태.
target_url string 상태와 연결된 타깃 URL.
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/17/statuses/18f3e63d05582537db6d183d9d557be09e1f90c8?state=success"

응답 예시:

{
  "author": {
    "web_url": "https://gitlab.example.com/janedoe",
    "name": "Jane Doe",
    "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
    "username": "janedoe",
    "state": "active",
    "id": 28
  },
  "name": "default",
  "sha": "18f3e63d05582537db6d183d9d557be09e1f90c8",
  "status": "success",
  "coverage": 100.0,
  "description": null,
  "id": 93,
  "target_url": null,
  "ref": null,
  "started_at": null,
  "created_at": "2016-01-19T09:05:50.355Z",
  "allow_failure": false,
  "finished_at": "2016-01-19T09:05:50.365Z"
}

커밋과 연결된 머지 리퀘스트 목록 조회#

히스토리

특정 커밋을 처음 도입한 머지 리퀘스트에 대한 정보를 반환합니다.

GET /projects/:id/repository/commits/:sha/merge_requests
Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 SHA.
state string No 지정한 상태의 머지 리퀘스트를 반환합니다: opened, closed, locked, merged. 이 파라미터를 생략하면 상태와 관계없이 모든 머지 리퀘스트를 가져옵니다.

성공 시 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
assignee object 머지 리퀘스트 담당자에 대한 정보.
author object 머지 리퀘스트 작성자에 대한 정보.
created_at string 머지 리퀘스트가 생성된 날짜.
description string 머지 리퀘스트에 대한 설명.
discussion_locked boolean true 이면 토론이 잠겨 있습니다.
downvotes integer 다운보트 수.
draft boolean true 이면 머지 리퀘스트가 드래프트 상태입니다.
force_remove_source_branch boolean true 이면 소스 브랜치를 강제로 제거합니다.
id integer 머지 리퀘스트의 ID.
iid integer 머지 리퀘스트의 내부 ID.
labels array 머지 리퀘스트와 연결된 레이블.
merge_commit_sha string 머지 커밋의 SHA.
merge_status string 머지 리퀘스트의 머지 상태.
merge_when_pipeline_succeeds boolean true 이면 파이프라인이 성공할 때 머지합니다.
milestone object 머지 리퀘스트와 연결된 마일스톤.
project_id integer 프로젝트의 ID.
sha string 머지 리퀘스트의 SHA.
should_remove_source_branch boolean true 이면 머지 후 소스 브랜치를 제거합니다.
source_branch string 머지 리퀘스트의 소스 브랜치.
source_project_id integer 소스 프로젝트의 ID.
squash_commit_sha string 스쿼시 커밋의 SHA.
state string 머지 리퀘스트의 상태.
target_branch string 머지 리퀘스트의 대상 브랜치.
target_project_id integer 타깃 프로젝트의 ID.
time_stats object 시간 추적 통계.
title string 머지 리퀘스트의 제목.
updated_at string 머지 리퀘스트가 마지막으로 업데이트된 날짜.
upvotes integer 업보트 수.
user_notes_count integer 사용자 노트 수.
web_url string 머지 리퀘스트의 웹 URL.
work_in_progress boolean true 이면 머지 리퀘스트가 진행 중인 작업으로 설정됩니다.
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/5/repository/commits/af5b13261899fb2c0db30abdd0af8b07cb44fdc5/merge_requests?state=opened"

응답 예시:

[
  {
    "id": 45,
    "iid": 1,
    "project_id": 35,
    "title": "Add new file",
    "description": "",
    "state": "opened",
    "created_at": "2018-03-26T17:26:30.916Z",
    "updated_at": "2018-03-26T17:26:30.916Z",
    "target_branch": "main",
    "source_branch": "test-branch",
    "upvotes": 0,
    "downvotes": 0,
    "author": {
      "web_url": "https://gitlab.example.com/janedoe",
      "name": "Jane Doe",
      "avatar_url": "https://gitlab.example.com/uploads/user/avatar/28/jane-doe-400-400.png",
      "username": "janedoe",
      "state": "active",
      "id": 28
    },
    "assignee": null,
    "source_project_id": 35,
    "target_project_id": 35,
    "labels": [],
    "draft": false,
    "work_in_progress": false,
    "milestone": null,
    "merge_when_pipeline_succeeds": false,
    "merge_status": "can_be_merged",
    "sha": "af5b13261899fb2c0db30abdd0af8b07cb44fdc5",
    "merge_commit_sha": null,
    "squash_commit_sha": null,
    "user_notes_count": 0,
    "discussion_locked": null,
    "should_remove_source_branch": null,
    "force_remove_source_branch": false,
    "web_url": "https://gitlab.example.com/root/test-project/merge_requests/1",
    "time_stats": {
      "time_estimate": 0,
      "total_time_spent": 0,
      "human_time_estimate": null,
      "human_total_time_spent": null
    }
  }
]

커밋 서명 조회#

커밋이 서명되어 있으면 커밋의 서명을 가져옵니다. 서명되지 않은 커밋은 404 응답을 반환합니다.

GET /projects/:id/repository/commits/:sha/signature

파라미터:

Attribute Type Required Description
id integer or string Yes 프로젝트의 ID 또는 URL 인코딩된 경로.
sha string Yes 커밋 해시 또는 리포지터리 브랜치나 태그의 이름.

성공 시 200 OK와 다음 응답 속성을 반환합니다.

Attribute Type Description
commit_source string 커밋의 소스.
gpg_key_id integer GPG 키의 ID(PGP 서명의 경우).
gpg_key_primary_keyid string GPG 키의 기본 키 ID.
gpg_key_subkey_id string GPG 키의 서브키 ID.
gpg_key_user_email string GPG 키와 연결된 이메일 주소.
gpg_key_user_name string GPG 키와 연결된 사용자 이름.
key object SSH 키 정보(SSH 서명의 경우).
signature_type string 서명 유형(PGP, SSH, X509).
verification_status string 서명의 검증 상태.
x509_certificate object X.509 인증서 정보(X.509 서명의 경우).
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/1/repository/commits/da738facbc19eb2fc2cef57c49be0e6038570352/signature"

커밋이 GPG로 서명된 경우의 응답 예시:

{
  "signature_type": "PGP",
  "verification_status": "verified",
  "gpg_key_id": 1,
  "gpg_key_primary_keyid": "8254AAB3FBD54AC9",
  "gpg_key_user_name": "John Doe",
  "gpg_key_user_email": "johndoe@example.com",
  "gpg_key_subkey_id": null,
  "commit_source": "gitaly"
}

커밋이 SSH로 서명된 경우의 응답 예시:

{
  "signature_type": "SSH",
  "verification_status": "verified",
  "key": {
    "id": 11,
    "title": "Key",
    "created_at": "2023-05-08T09:12:38.503Z",
    "expires_at": "2024-05-07T00:00:00.000Z",
    "key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILZzYDq6DhLp3aX84DGIV3F6Vf+Ae4yCTTz7RnqMJOlR MyKey)",
    "usage_type": "auth_and_signing"
  },
  "commit_source": "gitaly"
}

커밋이 X.509로 서명된 경우의 응답 예시:

{
  "signature_type": "X509",
  "verification_status": "unverified",
  "x509_certificate": {
    "id": 1,
    "subject": "CN=gitlab@example.org,OU=Example,O=World",
    "subject_key_identifier": "BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC:BC",
    "email": "gitlab@example.org",
    "serial_number": 278969561018901340486471282831158785578,
    "certificate_status": "good",
    "x509_issuer": {
      "id": 1,
      "subject": "CN=PKI,OU=Example,O=World",
      "subject_key_identifier": "AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB:AB",
      "crl_url": "http://example.com/pki.crl"
    }
  },
  "commit_source": "gitaly"
}

커밋이 서명되지 않은 경우의 응답 예시:

{
  "message": "404 GPG Signature Not Found"
}