Skip to content
Versora

Manual

History

Revert

4 min read

On this page

Revert creates a new commit that does the opposite of an earlier commit: what it added goes away, what it removed comes back. The original commit stays in the history, and nothing is rewritten.

It's the right way to undo a commit that has already been pushed and that other people may have fetched, for example a change that broke main. The push after the revert is a regular push.

To…UseRewrites history?
Cancel out a commit that has already been pushedRevertNo: it adds a commit
Remove a commit that hasn't been pushed yetDrop commitYes
Remove the branch's last commitsResetYes

Revert commit

Where to find it

  • A commit's menu (right-click in the graph) › Revert commit.
  • A branch's menu › Revert commit (applies to the commit at the tip of the branch).
  • The item is disabled on merge commits.

Step by step

  1. Check out the branch the revert should go into, usually the same as the commit's (for example main).
  2. Right-click the commit, for example c3d4e5f Switch the email provider.
  3. Choose Revert commit.
  4. Versora predicts whether there will be a conflict. Without a conflict, the revert runs right away ("Reverting…"). With a conflict expected, it shows the files first and asks.
  5. The new commit, with the title Revert "Switch the email provider", shows up at the top of the current branch.

The revert always goes into the current branch, even if the commit belongs to another branch.

What Versora does in git

bash
git revert --no-edit c3d4e5f

--no-edit accepts git's default message, without opening an editor: the title Revert "<commit title>" and the line This reverts commit <full SHA>. in the body. To change the message afterwards, use Edit commit message before the push.

If there's a conflict (another commit touched the same lines later), git stops. The changes panel shows the "Revert in progress" bar, with Continue, Skip and Abort (see Operation in progress).

How to undo

  • It finished without a conflict: Ctrl+Z ("Undo: Revert c3d4e5f") removes the revert commit. If it has already been pushed, don't undo it this way: revert the revert.
  • It stopped at a conflict: Abort puts everything back. If you resolved it and continued until the end (with Continue, through the commit box or even from the terminal), the whole revert goes into Ctrl+Z when it finishes, with the same name ("Undo: Revert c3d4e5f"), and removes what the revert created. The steps taken during the stop (resolving a file in the conflict editor, for example) leave the undo history at that point.

Caveats and messages

Conflict preview (when it's on and with git 2.40 or newer):

  • The title "The revert will conflict", with "Reverting c3d4e5f ("Switch the email provider") will conflict in 1 file:" and the list of files (up to eight; the rest becomes "• and N more").
  • "If you go ahead, the operation stops at the conflict and you resolve it in the conflict editor (Abort puts everything back)."
  • Revert anyway goes ahead; Cancel does nothing.

Merge commits: the item is disabled, because reverting a merge requires choosing which side to keep (git revert -m). Do it from the integrated terminal if you need to; see the git revert (opens another site) documentation.

  • Preferences › Operations › "Cherry-pick and revert" › Predict conflicts before cherry-pick and revert (on by default; needs git 2.40 or newer).
  • The company can hide or lock the Operations page through the policy (ergoOps in preferences.hidden or preferences.locked); see Company policy.

See also

Revert several commits

Cancels out several commits at once, with one revert commit for each, from newest to oldest.

Where to find it

  • Select the commits in the graph with Ctrl+click or Shift+click and open the selection menu › Revert 2 commits (the number follows the selection). See Multiple selection.

Step by step

  1. Select the commits, for example c3d4e5f Switch the email provider and d4e5f6a Adjust the email template.
  2. Right-click one of them and choose Revert 2 commits.
  3. If the preview finds a conflict, it says in which one: "Reverting commit 1 of 2, d4e5f6a ("Adjust the email template") will conflict in 1 file:". Confirm with Revert anyway or cancel.
  4. At the end: "Reverted 2 commits." The current branch gets two revert commits.

What Versora does in git

bash
git revert --no-edit d4e5f6a c3d4e5f    # from newest to oldest

Going from newest to oldest keeps a revert from running into the lines the following commit changed.

How to undo

Ctrl+Z ("Undo: Revert 2 commits") removes the revert commits, if the operation finished without stopping. If it stopped, Abort puts everything back.

Caveats and messages

When the selection doesn't work, the item shows the reason ("Revert 2 commits — reason"):

  • "an operation is in progress"
  • "the selection includes a stash"
  • "the selection includes a merge"

See also