doc/user/project/merge_requests/changes.md
{{< details >}}
{{< /details >}}
A merge request proposes a set of changes to files in a branch in your repository. GitLab shows these changes as a diff (difference) between the current state and the proposed changes. By default, the diff compares your proposed changes (the source branch) with the target branch. By default, GitLab shows only the changed portions of the files.
This example shows changes to a text file. In the default syntax highlighting theme:
-) sign before the line.+) sign before the line.The header for each file in the diff contains:
+2 -2.The diff also includes navigation and comment aids to the left of the file, in the gutter:
Use the file browser to view a list of files changed in a merge request:
To view the diff of changes included in a merge request:
GitLab collapses files with many changes to improve performance, and displays the message: Some changes are not shown. To view the changes for that file, select Expand file.
{{< details >}}
{{< /details >}}
{{< history >}}
pinned_file. Disabled by default.pinned_file removed.{{< /history >}}
When you share a merge request link with a team member, you might want to show a specific file first in the list of changed files. To copy a merge request link that shows your desired file first:
In the top bar, select Search or go to and find your project.
In the left sidebar, select Code > Merge requests and find your merge request.
Below the merge request title, select Changes.
Find the file you want to show first. Right-click the name of the file to copy the link to it.
When you visit that link, your chosen file is shown at the top of the list. The file browser shows a link icon ({{< icon name="link" >}}) next to the filename:
{{< details >}}
{{< /details >}}
{{< history >}}
collapse_generated_diff_files. Disabled by default.generated_file generally available in GitLab 16.11. Feature flag collapse_generated_diff_files removed.{{< /history >}}
To help reviewers focus on the files needed to perform a code review, GitLab collapses several common types of generated files. GitLab collapses these files by default, because they rarely require code reviews:
.nib, .xcworkspacedata, or .xcurserstate extensions.package-lock.json or Gopkg.lock.node_modules folder.js or css files.To mark a file or path as generated, set the gitlab-generated attribute for it
in your .gitattributes file.
To change the default collapse behavior for a file type:
If a .gitattributes file does not exist in the root directory of your project,
create a blank file with this name.
For each file type you want to modify, add a line to the .gitattributes file
declaring the file extension and your desired behavior:
# Collapse all files with a .txt extension
*.txt gitlab-generated
# Collapse all files within the docs directory
docs/** gitlab-generated
# Do not collapse package-lock.json
package-lock.json -gitlab-generated
Commit, push, and merge your changes into your default branch.
After the changes merge into your default branch, all files of this type in your project use this behavior in merge requests.
For technical details about how GitLab detects generated files, see the
go-enry repository.
For larger merge requests, you can review one file at a time. You can change this setting in your user preferences, or when you review a merge request. If you change this setting in a merge request, it updates your user settings as well.
{{< tabs >}}
{{< tab title="In a merge request" >}}
{{< /tab >}}
{{< tab title="In your user preferences" >}}
{{< /tab >}}
{{< /tabs >}}
To select another file to view when this setting is enabled, either:
You can view the changes in a merge request either:
To change how a merge request shows changed lines:
In the top bar, select Search or go to and find your project.
In the left sidebar, select Code > Merge requests and find your merge request.
Below the title, select Changes.
Select Preferences ({{< icon name="preferences" >}}). Select either Side-by-side or Inline. This example shows how GitLab renders the same change in both inline and side-by-side mode:
{{< tabs >}}
{{< tab title="Inline changes" >}}
{{< /tab >}}
{{< tab title="Side-by-side changes" >}}
{{< /tab >}}
{{< /tabs >}}
{{< details >}}
{{< /details >}}
{{< history >}}
rapid_diffs_on_mr_show. Disabled by default.{{< /history >}}
[!flag] The availability of this feature is controlled by a feature flag. For more information, see the history.
Rapid Diffs is a faster way to load and interact with code changes in merge requests. It reduces the time before you see the first file when reviewing a diff.
To turn on Rapid Diffs for all merge requests:
The page reloads with the new experience. Your preference persists across sessions.
To share feedback about Rapid Diffs, select Rapid Diffs > Leave feedback.
To turn off Rapid Diffs and switch back to the classic diff loading experience:
{{< details >}}
{{< /details >}}
{{< collapsible title="Model information" >}}
{{< /collapsible >}}
{{< history >}}
{{< /history >}}
If you spend a lot of time trying to understand code that others have created, or you struggle to understand code written in a language you are not familiar with, you can ask GitLab Duo to explain the code to you.
Prerequisites:
To explain the code in a merge request:
In the top bar, select Search or go to and find your project.
In the left sidebar, select Code > Merge requests, then select your merge request.
Select Changes.
On the file you would like explained, select the three dots ({{< icon name="ellipsis_v" >}}) and select View File @ $SHA.
A separate browser tab opens and shows the full file with the latest changes.
On the new tab, select the lines you want to have explained.
On the left side, select the question mark ({{< icon name="question" >}}). You might have to scroll to the first line of your selection to view it.
GitLab Duo Chat explains the code. It might take a moment for the explanation to be generated.
If you'd like, you can provide feedback about the quality of the explanation.
GitLab cannot guarantee that the large language model produces results that are correct. Use the explanation with caution.
You can also explain code in:
When reviewing code changes, you can hide inline comments:
To expand inline comments and show them again:
Whitespace changes can make it more difficult to see the substantive changes in a merge request. You can choose to hide or show whitespace changes:
In the top bar, select Search or go to and find your project.
In the left sidebar, select Code > Merge requests and find your merge request.
Below the title, select Changes.
Before the list of changed files, select Preferences ({{< icon name="preferences" >}}).
Select or clear Show whitespace changes:
When reviewing a merge request with many files multiple times, you can ignore files you've already reviewed. To hide files that haven't changed after your last review:
Files marked as viewed are not shown to you again unless either:
To avoid displaying changes already on target branch, GitLab compares the merge request's
source branch with the HEAD of the target branch.
When the source and target branch conflict, GitLab show an alert per conflicted file on the merge request diff:
{{< details >}}
{{< /details >}}
You can show scanner findings in the diff. For details, see:
You can download the changes included in a merge request for use outside of GitLab.
To download the changes as a diff:
If you know the URL of the merge request, you can also download the diff from
the command line by appending .diff to the URL. This example downloads the diff
for merge request 000000:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/000000.diff
To download and apply the diff in a one-line CLI command:
curl "https://gitlab.com/gitlab-org/gitlab/-/merge_requests/000000.diff" | git apply
To download the changes as a patch file:
If you know the URL of the merge request, you can also download the patch from
the command line by appending .patch to the URL. This example downloads the patch
file for merge request 000000:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/000000.patch
To download and apply the patch using git am:
# Download and preview the patch
curl "https://gitlab.com/gitlab-org/gitlab/-/merge_requests/000000.patch" > changes.patch
git apply --check changes.patch
# Apply the patch
git am changes.patch
You can also download and apply the patch in a single command:
curl "https://gitlab.com/gitlab-org/gitlab/-/merge_requests/000000.patch" | git am
The git am uses the -p1 option by default. For more information, see git-apply.
{{< history >}}
{{< /history >}}
To download older diff versions as a patch or diff file:
.diff or .patch to the URL path.For example:
# As a diff file:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/123456/diffs.diff?diff_id=525410&start_sha=a1b2c3d4
# As a patch file:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/123456/diffs.patch?diff_id=525410&start_sha=a1b2c3d4
{{< history >}}
comment_on_files. Enabled by default.{{< /history >}}
You can add comments to a merge request diff file. These comments persist across rebases and file changes.
To add a comment to a merge request file:
In merge requests and commit detail views, you can add a comment to an image. This comment can also be a thread.
GitLab shows an icon and a comment field on the image.