debian-mirror-gitlab/doc/user/project/merge_requests/revert_changes.md
2023-01-13 15:02:22 +05:30

4.2 KiB

stage group info
Create Code Review To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments

Revert changes (FREE)

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 > General > Merge request. You can't revert fast-forwarded commits from the GitLab UI.

To do this:

  1. On the top bar, select Main menu > Projects and find your project.
  2. On the left sidebar, select Merge requests and identify your merge request.
  3. Scroll to the merge request reports area, and find the report showing when the merge request was merged.
  4. Select Revert.
  5. In Revert in branch, select the branch to revert your changes into.
  6. Optional. Select Start a new merge request to start a new merge request with the new revert commit.
  7. 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.

To do this:

  1. On the top bar, select Main menu > Projects and find your project.
  2. If you know the merge request that contains the commit:
    1. On the left sidebar, select Merge requests and identify your merge request.
    2. Select Commits, then select the title of the commit you want to revert. GitLab displays the contents of the commit.
  3. If you don't know the merge request the commit originated from:
    1. On the left sidebar, select Repository > Commits.
    2. Select the title of the commit to display full information about the commit.
  4. In the top right corner, select Options, then select Revert.
  5. In Revert in branch, select the branch to revert your changes into.
  6. Optional. Select Start a new merge request to start a new merge request with the new revert commit.
  7. Select Revert.

The option to Revert is no longer shown after a commit is reverted.

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:

  1. Identify the SHA of the parent commit you want to revert to.

  2. Identify the parent number of the commit you want to revert to. (Defaults to 1, for the first parent.)

  3. Modify this command, replacing 2 with the parent number, and 7a39eb0 with the commit SHA:

    git revert -m 2 7a39eb0