Reverting Branches

A revert is a type of commit that undoes a prior commit on your branch. Reverting becomes necessary if changes have been made that are no longer needed. For example, if you have committed changes for a feature branch that is no longer going to be included in a release, those changes need to be reverted.

In the Source Control ribbon, the Branch History button displays your history of commits on the active Git branch. This dialog displays the history in descending order, with the most recent action displayed on the top line.

An advantage of reverting a prior commit on your branch is that it will back out any unwanted changes. If other writers are making changes on the same branch, any reverted commits will be picked up by the other writers when they pull from that branch. See Pulling Files From a Remote Repository—Git.

But one disadvantage of reverting commits in your branch is that it will remove part of your branch history. The revert removes the part of your branch history that contained the commits that were undone.

How to Revert Commits in a Git Branch

  1. In the Source Control Explorer, select your branch containing changes that you want to revert. See Switching Branches.
  2. In the Source Control ribbon, click Branch History. The dialog that opens lets you view and revert specific commits within your branch.

    The following columns are displayed:

    • Commit Type This indicates the type of changes checked in on the branch. You can view when a branch was started, when a commit was made, or when a merge occurred.
    • Branches This column displays the branches that are affected by the action taken. If the changes affect more than one branch then all of the affected branches are displayed in this column.
    • Commit This alphanumerical code provides the commit number used by Git.
    • Commit Time This displays the date, followed by the time the commit was made in your Git branch.
    • Author This displays the name of the author that committed the specific change in the branch.
    • Comments This column displays the comments made for each commit.
  3. Select the row that contains the commit you want to back out.
  4. Click Revert.The Accept reverted modifications dialog is displayed.

  5. Click Accept.
  6. A confirmation message confirms the revert was successful. Click OK to close this dialog.