Skip to content
Software capabilities

GitLab capability

Read a GitLab merge request diff

Use the Merge Requests API to get diffs and metadata by file. Use glab mr diff --raw when a patch tool needs the original patch format.

Documentation reviewed

Ways to do it

API

GET /projects/{id}/merge_requests/{merge_request_iid}/diffs

Read per-file changes, paths, and flags for added, removed, or renamed files.

Requirements
Project ID or URL-encoded path, project-scoped merge request IID, and API read access.
Limitations
GitLab can omit diff content for files marked collapsed or too_large. A file entry alone doesn’t guarantee its changes are present.
Read source: GitLab Merge Requests API list diffs

CLI

glab mr diff <iid> --raw

Print a merge request’s raw diff for a patch tool or another script.

Requirements
glab authenticated to the project and the merge request IID or branch.
Limitations
The raw output is a patch. Use the API when the program needs per-file metadata as JSON.

Example

glab mr diff "$MR_IID" --repo "$PROJECT_PATH" --raw
Read source: GitLab CLI mr diff