Revert Commits

You can undo committed changes by reverting one or more commits from your repository's history. Reverting can help you undo commits that perhaps introduced a bug, or back out changes that were accidentally merged to your repository's branch.

When a commit is reverted, the changes from the particular commit are removed from your local workspace, and a new commit is created to reflect your repository as it stands with the removed commits. This way, it's possible to even undo a revert.

Before you revert commits, make sure you commit or stash any pending changes in your workspace if you need them, or reset or rollback changes if you don't need them.

To revert one or more commits:

  1. Click the Git menu in the header or in the Git panel.
  2. Select Revert Commits.
  3. In the Revert Commits dialog, select one or more commits to revert in the current branch. Use the details pane on the right to view the changes in each commit. Details of the commit you last selected will show:

    Note that reverting merge commits (those that have more than one parent) is not supported, so you won't see those commits in the Revert Commits dialog.
  4. Optional: As a best practice, select Create a new branch for this revert, and enter the name of the branch that will be created based on the current branch (for example, revert/ExperimentalChange). Creating a separate branch is recommended when you want to isolate your changes to a particular branch in your local workspace and later create a code review on them (merge request), or deploy the changes for testing before merging them to their target.
  5. Click Revert.
    • If your commits were successfully reverted, you'll see a notification in the lower right corner.
    • If you run into conflicts, you'll need to first resolve the conflicts. Click Show Conflicts to open the Git panel and resolve the conflicts. Once you do that, click Continue to proceed with your revert.
      Description of revertcommit-conflict.png follows
      Description of the illustration revertcommit-conflict.png

      Alternatively, click Abort to discard the current revert operation for all selected commits, which resets the branch to its state before the revert operation was started. This means:
      • Any commits reverted during the current operation are removed,
      • Any conflicts in files are reset, and
      • Any pending commits that were to be reverted after this commit are canceled.

      Once aborted, you'll need to start another revert operation with the commits you want.

  6. Click Git History to check your Git actions. Here's an example of a revert operation for two commits, where one commit was successfully reverted and the other was interrupted because of conflicts; once the conflict is resolved and the operation continued, the commit is successfully marked as reverted: