InfoGrab DocsInfoGrab Docs

Commits API

요약

이 API를 사용하여 Git 커밋을 관리합니다. 이 API의 응답에서 일부 날짜 필드는 중복된 정보처럼 보일 수 있습니다. created_at 필드는 다른 GitLab API와의 일관성을 위해서만 존재합니다. committed_date와 authored_date 필드는 서로 다른 소스에서 생성되므로 동일하지 않을 수 있습니다.

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

응답#

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

  • created_at 필드는 다른 GitLab API와의 일관성을 위해서만 존재합니다. 이 필드는 항상 committed_date 필드와 동일합니다.

  • committed_dateauthored_date 필드는 서로 다른 소스에서 생성되므로 동일하지 않을 수 있습니다.

페이지네이션 응답 헤더#

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

  • x-total

  • x-total-pages

자세한 내용은 이슈 389582를 참조하세요.

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

히스토리

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

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.7에서 요청 크기 및 속도 제한이 도입됨.

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

POST /projects/:id/repository/commits

이 엔드포인트는 요청 크기 및 속도 제한의 적용을 받습니다. 기본 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 기반의 새 커밋으로 브랜치를 덮어씁니다. 브랜치의 기존 커밋 히스토리를 대체합니다. 기본값은 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입니다.

각주:

  • forcetrue이면, 다른 부모 커밋을 지정하기 위해 start_branch 또는 start_sha를 제공하세요. 어느 것도 제공하지 않으면 start_branchbranch의 값으로 기본 설정되며, 새 커밋은 현재 브랜치 팁을 기반으로 합니다. 이 경우 결과가 일반 커밋과 동일하므로 force는 효과가 없습니다.

많은 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"
}

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

커밋이 푸시된 모든 참조(브랜치 또는 태그)를 나열합니다. 페이지네이션 파라미터 pageper_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에서 collapsedtoo_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입니다. GitLab 16.5에서 도입됨.

이 엔드포인트는 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_typenew여야 합니다.

다음 중 하나라도 유효한 경우 코멘트는 마지막 커밋의 끝에 추가됩니다.

  • sha가 브랜치 또는 태그이고 line 또는 path가 유효하지 않은 경우

  • line 번호가 유효하지 않은 경우(존재하지 않음)

  • path가 유효하지 않은 경우(존재하지 않음)

위의 경우 중 어느 하나에 해당하면, 응답의 line, line_typepathnull로 설정됩니다.

머지 리퀘스트에 코멘트를 달기 위한 다른 방법은 노트 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 필드가 도입됨.

프로젝트에서 커밋의 상태를 나열합니다. 페이지네이션 파라미터 pageper_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로 새 파이프라인이 생성됩니다.

자세한 내용은 외부 커밋 상태를 참조하세요.

동일한 커밋에 중복 파이프라인이 있는 경우, 어느 파이프라인이 외부 상태를 받는지 모호할 수 있습니다. 파이프라인을 구성하여 중복을 방지하세요.

파이프라인이 이미 존재하고 단일 파이프라인의 최대 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 squash 커밋의 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.1
Tier: Free, Premium, Ultimate
Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
원문 보기
요약

이 API를 사용하여 Git 커밋을 관리합니다. 이 API의 응답에서 일부 날짜 필드는 중복된 정보처럼 보일 수 있습니다. created_at 필드는 다른 GitLab API와의 일관성을 위해서만 존재합니다. committed_date와 authored_date 필드는 서로 다른 소스에서 생성되므로 동일하지 않을 수 있습니다.

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

응답#

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

  • created_at 필드는 다른 GitLab API와의 일관성을 위해서만 존재합니다. 이 필드는 항상 committed_date 필드와 동일합니다.

  • committed_dateauthored_date 필드는 서로 다른 소스에서 생성되므로 동일하지 않을 수 있습니다.

페이지네이션 응답 헤더#

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

  • x-total

  • x-total-pages

자세한 내용은 이슈 389582를 참조하세요.

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

히스토리

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

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.7에서 요청 크기 및 속도 제한이 도입됨.

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

POST /projects/:id/repository/commits

이 엔드포인트는 요청 크기 및 속도 제한의 적용을 받습니다. 기본 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 기반의 새 커밋으로 브랜치를 덮어씁니다. 브랜치의 기존 커밋 히스토리를 대체합니다. 기본값은 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입니다.

각주:

  • forcetrue이면, 다른 부모 커밋을 지정하기 위해 start_branch 또는 start_sha를 제공하세요. 어느 것도 제공하지 않으면 start_branchbranch의 값으로 기본 설정되며, 새 커밋은 현재 브랜치 팁을 기반으로 합니다. 이 경우 결과가 일반 커밋과 동일하므로 force는 효과가 없습니다.

많은 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"
}

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

커밋이 푸시된 모든 참조(브랜치 또는 태그)를 나열합니다. 페이지네이션 파라미터 pageper_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에서 collapsedtoo_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입니다. GitLab 16.5에서 도입됨.

이 엔드포인트는 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_typenew여야 합니다.

다음 중 하나라도 유효한 경우 코멘트는 마지막 커밋의 끝에 추가됩니다.

  • sha가 브랜치 또는 태그이고 line 또는 path가 유효하지 않은 경우

  • line 번호가 유효하지 않은 경우(존재하지 않음)

  • path가 유효하지 않은 경우(존재하지 않음)

위의 경우 중 어느 하나에 해당하면, 응답의 line, line_typepathnull로 설정됩니다.

머지 리퀘스트에 코멘트를 달기 위한 다른 방법은 노트 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 필드가 도입됨.

프로젝트에서 커밋의 상태를 나열합니다. 페이지네이션 파라미터 pageper_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로 새 파이프라인이 생성됩니다.

자세한 내용은 외부 커밋 상태를 참조하세요.

동일한 커밋에 중복 파이프라인이 있는 경우, 어느 파이프라인이 외부 상태를 받는지 모호할 수 있습니다. 파이프라인을 구성하여 중복을 방지하세요.

파이프라인이 이미 존재하고 단일 파이프라인의 최대 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 squash 커밋의 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"
}