repositories

Compare branches, tags, or commits

Compares branches, tags, or commits. Retrieves the differences between two branches, tags, or commits in a specified project.

get/api/v4/projects/{id}/repository/compare

Request

  • Base URL
    https://gitlab.com
  • Auth
    none declared

Path parameters

idstring required

The ID or URL-encoded path of the project

Query parameters

fromstring required

The commit, branch name, or tag name to start comparison

tostring required

The commit, branch name, or tag name to stop comparison

from_project_idinteger

The project to compare from

straightboolean

Comparison method, true for direct comparison between from and to (from..to), false to compare using merge base (from...to)

unidiffboolean

A diff in a Unified diff format

Response

Compare branches, tags, or commits

compare_timeoutboolean required
compare_same_refboolean required
web_urlstring required

Example response

{
  "commit": {
    "id": "2695effb5807a22ff3d138d593fd856244e155e7",
    "short_id": "2695effb",
    "created_at": "2017-07-26T11:08:53.000+02:00",
    "parent_ids": [
      "2a4b78934375d7f53875269ffd4f45fd83a84ebe"
    ],
    "title": "Initial commit",
    "message": "Initial commit",
    "author_name": "John Smith",
    "author_email": "john@example.com",
    "authored_date": "2012-05-28T04:42:42-07:00",
    "committer_name": "Jack Smith",
    "committer_email": "jack@example.com",
    "committed_date": "2012-05-28T04:42:42-07:00",
    "trailers": {
      "Merged-By": "Jane Doe janedoe@gitlab.com"
    },
    "extended_trailers": {
      "Signed-off-by": [
        "John Doe <johndoe@gitlab.com>",
        "Jane Doe <janedoe@gitlab.com>"
      ]
    },
    "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
  },
  "commits": [
    {
      "id": "2695effb5807a22ff3d138d593fd856244e155e7",
      "short_id": "2695effb",
      "created_at": "2017-07-26T11:08:53.000+02:00",
      "parent_ids": [
        "2a4b78934375d7f53875269ffd4f45fd83a84ebe"
      ],
      "title": "Initial commit",
      "message": "Initial commit",
      "author_name": "John Smith",
      "author_email": "john@example.com",
      "authored_date": "2012-05-28T04:42:42-07:00",
      "committer_name": "Jack Smith",
      "committer_email": "jack@example.com",
      "committed_date": "2012-05-28T04:42:42-07:00",
      "trailers": {
        "Merged-By": "Jane Doe janedoe@gitlab.com"
      },
      "extended_trailers": {
        "Signed-off-by": [
          "John Doe <johndoe@gitlab.com>",
          "Jane Doe <janedoe@gitlab.com>"
        ]
      },
      "web_url": "https://gitlab.example.com/janedoe/gitlab-foss/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
    }
  ],
  "diffs": [
    {
      "diff": "@@ -71,6 +71,8 @@\\n...",
      "new_path": "doc/update/5.4-to-6.0.md",
      "old_path": "doc/update/5.4-to-6.0.md",
      "a_mode": "100755",
      "b_mode": "100644"
    }
  ],
  "web_url": "https://gitlab.example.com/gitlab/gitlab-foss/-/compare/main...feature"
}

Changes

No recorded changes to this operation across all 5 revisions of this API.