Changes in merge requests (FREE ALL)
A merge request proposes a set of changes to files in a branch in your repository. These changes are shown as a diff (difference) between the current state and the proposed changes.
By default, the diff view compares the versions of files in the merge request source branch to the files in the target branch, and shows only the parts of a file that have changed.
For technical details on how GitLab calculates the diff between the two revisions, read Working with diffs in our development documentation.
Show all changes in a merge request
To view the diff of changes included in a merge request:
- Go to your merge request.
- Below the merge request title, select Changes.
- If the merge request changes many files, you can jump directly to a specific file:
- Select Show file browser ({file-tree}) or press F to display the file tree.
- Select the file you want to view.
- To hide the file browser, select Show file browser or press F again.
Files with many changes are collapsed to improve performance. GitLab displays the message: Some changes are not shown. To view the changes for that file, select Expand file.
Show one file at a time
For larger merge requests, you can review one file at a time. You can change this setting temporarily in a merge request, or so it applies to all merge requests.
In a merge request, show only one file at a time
To temporarily change your viewing preferences for a specific merge request:
- Go to your merge request, and below the merge request title, select Changes.
- Select Preferences ({settings}).
- Select or clear the Show one file at a time checkbox.
This change overrides your choice in your user preferences. It persists until you clear your browser's cookies or change this behavior again.
In all merge requests, show only one file at a time
To view one file at a time for all of your merge requests:
- On the left sidebar, select your avatar.
- Select Preferences.
- Scroll to the Behavior section and select the Show one file at a time on merge request's Changes tab checkbox.
- Select Save changes.
After you enable this setting, GitLab displays only one file at a time when you review merge requests. To view other changed files, either:
- Scroll to the end of the file and select either Prev or Next.
- Select Show file browser ({file-tree}) and select another file to view.
Compare changes inline
You can view the changes inline:
- Go to your merge request, and below the title, select Changes.
- Select Preferences ({settings}).
- In the Compare changes area, select Inline.
The changes are displayed after the original text.
Compare changes side-by-side
Depending on the length of the changes in your merge request, you may find it easier to view the changes inline, or side-by-side:
- Go to your merge request, and below the title, select Changes.
- Select Preferences ({settings}).
- In the Compare changes area, select Side-by-side.
The changes are displayed across from one another.
Expand or collapse comments
When reviewing code changes, you can hide inline comments:
- Go to your merge request, and below the title, select Changes.
- Scroll to the file that contains the comments you want to hide.
- Scroll to the line the comment is attached to, and select Collapse ({collapse}):
To expand inline comments and show them again:
- Go to your merge request, and below the title, select Changes.
- Scroll to the file that contains the collapsed comments you want to show.
- Scroll to the line the comment is attached to, and select the user avatar:
Ignore whitespace changes
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:
-
Go to your merge request, and below the title, select Changes.
-
Before the list of changed files, select Preferences ({settings}).
-
Select or clear the Show whitespace changes checkbox:
Mark files as viewed
- Introduced in GitLab 13.9 with a flag named
local_file_reviews
. Enabled by default.- Feature flag removed in GitLab 14.3.
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 since your last review:
- Go to your merge request, and below the title, select Changes.
- In the file's header, select the Viewed checkbox.
Files marked as viewed are not shown to you again unless either:
- New changes are made to its content.
- You clear the Viewed checkbox.
Show merge request conflicts in diff
- Introduced in GitLab 13.5 with a flag named
display_merge_conflicts_in_diff
. Disabled by default.- Enabled on GitLab.com and self-managed in GitLab 15.7.
- Generally available in GitLab 15.8. Feature flag
display_merge_conflicts_in_diff
removed.
To avoid displaying the changes that are already on target branch in the diff, we compare the merge request's source branch with HEAD of the target branch.
When there are conflicts between the source and target branch, we show an alert per conflicted file on the merge request diff:
Add a comment to a merge request file
- Introduced in GitLab 16.1 with a flag named
comment_on_files
. Enabled by default.- Feature flag removed in GitLab 16.2.
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:
- On the left sidebar, at the top, select Search GitLab ({search}) to find your project.
- Select Code > Merge requests and find your merge request.
- Select Changes.
- In the header for the file you want to comment on, select Comment ({comment}).
Add a comment to an image
In merge requests and commit detail views, you can add a comment to an image. This comment can also be a thread.
- Hover your mouse over the image.
- Select the location where you want to comment.
An icon is displayed on the image and a comment field is displayed.