doc/user/project/merge_requests/reviews/suggestions.md
{{< details >}}
{{< /details >}}
Reviewers can suggest code changes with a Markdown syntax in merge request diff threads. The merge request author (or other users with the appropriate role) can apply any or all suggestions from the GitLab UI. Applying suggestions adds a commit to the merge request, authored by the user who suggested the 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.
On the secondary menu, select Changes.
Find the lines of code you want to change.
Hover over the line number, and select Add a comment to this line ({{< icon name="comment" >}}):
Select and drag your selection to include all desired lines. For more information, see multi-line suggestions.
In the comment toolbar, select Insert suggestion ({{< icon name="doc-code" >}}). GitLab inserts a pre-populated code block into your comment, like this:
```suggestion:-0+0
The content of the line you selected is shown here.
```
Edit the pre-populated code block to add your suggestion.
To add your comment immediately, select Add comment now, or use the keyboard shortcut:
To leave your comment unpublished until you finish a review, select Start a review, or use the keyboard shortcut:
{{< history >}}
{{< /history >}}
When you review a merge request diff, you can propose changes to multiple lines (up to 200) in a single suggestion, by either:
The range offsets in the first line of the suggestion describe line numbers relative to the line you selected. The offsets specify the lines your suggestion intends to replace. For example, this suggestion covers 2 lines above and 2 lines below the commented line:
```suggestion:-2+2
## Prevent approval by author
By default, the author of a merge request cannot approve it. To change this setting:
```
When applied, the suggestion replaces from 2 lines above to 2 lines below the commented line:
GitLab limits multi-line suggestions to 100 lines above and 100 lines below the commented diff line. This allows for up to 201 changed lines per suggestion.
Multi-line comments display the comment's line numbers above the body of the comment:
{{< history >}}
content_editor_on_issues. Disabled by default.content_editor_on_issues removed in GitLab 16.5.{{< /history >}}
When you insert suggestions, use the WYSIWYG rich text editor to move up and down the source file's line numbers in the UI.
To add or subtract changed lines, next to From line, select + or -.
Prerequisites:
To apply suggested changes directly from the merge request:
After you apply a suggestion, GitLab:
Prerequisites:
To reject a suggested change directly from the merge request:
GitLab uses a default commit message when applying suggestions, but you can change
it. This message supports placeholders. For example, the default message
Apply %{suggestions_count} suggestion(s) to %{files_count} file(s) renders
like this if you apply three suggestions to two different files:
Apply 3 suggestion(s) to 2 file(s)
Merge requests created from forks use the template defined in the target project. To meet your project's needs, customize these messages and include other placeholder variables.
Prerequisites:
To do this:
The template for commit messages for applied suggestions supports these variables:
| Variable | Description | Output example |
|---|---|---|
%{branch_name} | The name of the branch to which suggestions were applied. | my-feature-branch |
%{files_count} | The number of files to which suggestions were applied. | 2 |
%{file_paths} | The paths of the file to which suggestions were applied. Paths are separated by commas. | docs/index.md, docs/about.md |
%{project_path} | The project path. | my-group/my-project |
%{project_name} | The human-readable name of the project. | My Project |
%{suggestions_count} | The number of suggestions applied. | 3 |
%{username} | The username of the user applying suggestions. | user_1 |
%{user_full_name} | The full name of the user applying suggestions. | User 1 |
%{co_authored_by} | Names and emails of suggestion authors in a Co-authored-by Git commit trailer format. | Co-authored-by: Zane Doe <[email protected]> |
Co-authored-by: Blake Smith <[email protected]> |
For example, to customize the commit message to output
Addresses user_1's review, set the custom text to
Addresses %{username}'s review.
Prerequisites:
To reduce the number of commits added to your branch, apply multiple suggestions in a single commit.
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.
For each suggestion you want to apply, select Add suggestion to batch.
Optional. To remove a suggestion, select Remove from batch.
After you add your desired suggestions, select Apply suggestions.
[!warning] If you apply a batch of suggestions containing changes from multiple authors, the resulting commit credits you as the author. If you configure your project to prevent approvals from users who add commits, you are no longer an eligible approver for this merge request.
Optional. Provide a custom commit message for batch suggestions to describe your change. If you don't specify one, it uses the default commit message.