Revert changes
DETAILS: Tier: Free, Premium, Ultimate Offering: SaaS, self-managed
You can revert individual commits or an entire merge request in GitLab. When you revert a commit in Git, you create a new commit that reverses all actions taken in the original commit:
- Lines added in the original commit are removed.
- Lines removed in the original commit are added back.
- Lines modified in the original commit are restored to their previous state.
Your revert commit is still subject to your project's access controls and processes.
Revert a merge request
After a merge request is merged, you can revert all changes in the merge request.
Prerequisites:
-
You must have a role in the project that allows you to edit merge requests, and add code to the repository.
-
Your project must use the merge method Merge Commit, which is set in the project's Settings > Merge requests.
In GitLab 16.9 and later, you can revert fast-forwarded commits from the GitLab UI only when they are squashed or when the merge request contains a single commit.
To do this:
- On the left sidebar, select Search or go to and find your project.
- Select Code > Merge requests and identify your merge request.
- Scroll to the merge request reports area, and find the report showing when the merge request was merged.
- Select Revert.
- In Revert in branch, select the branch to revert your changes into.
- Optional. Select Start a new merge request to start a new merge request with the new revert commit.
- Select Revert.
The option to Revert is no longer shown after a merge request is reverted.
Revert a commit
You can revert any commit in a repository into either:
- The current branch.
- A new merge request.
Prerequisites:
- You must have a role in the project that allows you to edit merge requests, and add code to the repository.
- The commit must not have already been reverted, as the Revert option is not shown in this case.
To do this:
- On the left sidebar, select Search or go to and find your project.
- If you know the merge request that contains the commit:
- Select Code > Merge requests, then select your merge request.
- Select Commits, then select the title of the commit you want to revert. This displays the commit in the context of your merge request.
- Below the secondary menu, the message Viewing commit
00001111
is shown, where00001111
is the hash of the commit. Select the commit hash to show the commit's page.
- If you don't know the merge request the commit originated from:
- Select Code > Commits.
- Select the title of the commit to display full information about the commit.
- In the upper-right corner, select Options, then select Revert.
- In Revert in branch, select the branch to revert your changes into.
- Optional. Select Start a new merge request to start a new merge request with the new revert commit.
- Select Revert.
Revert a merge commit to a different parent commit
When you revert a merge commit, the branch you merged to (usually main
) is always the
first parent. To revert a merge commit to a different parent,
you must revert the commit from the command line:
-
Identify the SHA of the parent commit you want to revert to.
-
Identify the parent number of the commit you want to revert to. (Defaults to 1, for the first parent.)
-
Modify this command, replacing
2
with the parent number, and7a39eb0
with the commit SHA:git revert -m 2 7a39eb0