- Create suggestions
- Apply suggestions
- Nest code blocks in suggestions
- Configure the commit message for applied suggestions
- Batch suggestions
- Related topics
Suggest changes
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.
Create suggestions
- On the left sidebar, select Search or go to and find your project.
- Select Code > Merge requests and find your merge request.
- On the secondary menu, select Changes.
- Find the lines of code you want to change.
- To select a single line, hover over the line number and select Add a comment to this line ().
- To select multiple lines:
- Hover over the line number, and select Add a comment to this line ():
- Select and drag your selection to include all desired lines. To learn more, see Multi-line suggestions.
-
In the comment toolbar, select Insert suggestion (). 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:
- macOS: Shift + Command + Enter
- All other OSes: Shift + Control + Enter
- To leave your comment unpublished until you finish a review, select
Start a review, or use the keyboard shortcut:
- macOS: Command + Enter
- All other OSes: Control + Enter
Multi-line suggestions
When you review a merge request diff, you can propose changes to multiple lines (up to 200) in a single suggestion, by either:
- Selecting and dragging, as described in Create suggestions. GitLab creates a suggestion block for you.
- Selecting a single line, then manually editing the range offsets in the suggestion block.
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:
Suggestions for multiple lines are limited to 100 lines above and 100 lines below the commented diff line. This allows for up to 201 changed lines per suggestion.
Multiline comments display the comment’s line numbers above the body of the comment:
Using the rich text editor
-
Introduced in GitLab 16.1 with a flag named
content_editor_on_issues
. Disabled by default. - Enabled on GitLab.com and self-managed in GitLab 16.2.
- Feature flag
content_editor_on_issues
removed in GitLab 16.5.
When you insert suggestions, you can 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 -.
Apply suggestions
Prerequisites:
- You must be the author of the merge request, or have at least the Developer role for the project.
To apply suggested changes directly from the merge request:
- On the left sidebar, select Search or go to and find your project.
- Select Code > Merge requests and find your merge request.
- Find the comment containing the suggestion you want to apply.
- To apply suggestions individually, select Apply suggestion.
- To apply multiple suggestions in a single commit, select Add suggestion to batch.
- Optional. Provide a custom commit message to describe your change. If you don’t provide a custom message, it uses the default commit message.
- Select Apply.
After you apply a suggestion, GitLab:
- Marks the suggestion as Applied.
- Resolves the comment thread.
- Creates a new commit with the changes.
- (If the user has the Developer role) Pushes the suggested change directly into the codebase in the merge request’s branch.
Nest code blocks in suggestions
To add a suggestion that includes a fenced code block, wrap your suggestion in four backticks instead of three:
````suggestion:-0+2
```shell
git config --global receive.advertisepushoptions true
```
````
Configure the commit message for applied suggestions
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:
- You must have the Maintainer role.
To do this:
- On the left sidebar, select Search or go to and find your project.
- Select Settings > Merge requests.
- Scroll to Merge suggestions, and alter the text to meet your needs. See Supported variables for a list of placeholders you can use in this message.
Supported variables
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 <zdoe@example.com> Co-authored-by: Blake Smith <bsmith@example.com>
|
For example, to customize the commit message to output
Addresses user_1's review
, set the custom text to
Addresses %{username}'s review
.
Batch suggestions
Prerequisites:
- You must have a role for the project that allows you to commit to the source branch.
To reduce the number of commits added to your branch, apply multiple suggestions in a single commit.
- On the left sidebar, select Search or go to and find your project.
- 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.
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.