Skip to content
Versora

Manual

Undo

Undo and redo

11 min read

On this page

In Versora, Ctrl+Z undoes the last git operation done in the app, not just the last thing you typed. Made a commit on the wrong branch, a merge you didn't want, a hard reset, or discarded a file by accident? Ctrl+Z takes the repository back to how it was before, and Ctrl+Shift+Z redoes it.

How it works: before each operation, the app takes a snapshot of the repository's state (where HEAD is, where each branch and each tag points, which stashes exist). Before operations that discard uncommitted changes, it also keeps a copy of the files. Undoing means taking the repository back to the snapshot from before; redoing, to the snapshot from after.

Where to find it

  • Shortcut: Ctrl+Z, outside a text field. Inside a field (the commit message, the result in the conflict editor), Ctrl+Z undoes the typing.
  • Toolbar, on the right: the undo button. The tooltip says what it will undo, for example "Undo: Commit "Fix login" (Ctrl+Z)". With nothing to undo, "Nothing to undo", and the button is disabled.
  • Palette (Ctrl+P): "Undo", with the detail "Undoes: Commit "Fix login"".
  • Timeline (Alt+Z): to undo several steps at once, seeing first what changes.

Step by step

  1. Right after the operation, press Ctrl+Z (with the focus outside a text field) or click the undo button.
  2. The indicator shows "Undoing…".
  3. The notice confirms: "Undone: Commit "Fix login"". If there was nothing: "Nothing to undo."
  4. Repeat to undo the previous operation, and so on.

What Ctrl+Z undoes

Every operation done by the app that changes local branches, tags, stashes or HEAD, or that discards files with a copy beforehand, goes into the undo history. The main ones:

OperationWhat undo does
Commit (including amend)The branch goes back to the previous commit and the commit's changes go back to the stage: nothing is lost.
Merge, pull, rebase, squash merge, cherry-pick, revert (finished without stopping)The branch goes back to where it was, and so do the files.
A merge, rebase, cherry-pick or revert that stopped (conflict, hook, stop to edit) and was finished later: with Continue, with the commit, with Finish the merge without hooks or even from the terminalThe whole operation is removed at once: the branch and the files go back to before it. See "Stopped operations", below.
Interactive rebase, edit message, drop and move commits, commit surgeryThe branch goes back to the previous history.
Soft, mixed or hard resetThe branch goes back, in the same mode as the reset. With hard, the uncommitted changes the reset threw away come back from the copy.
Checkout (of a branch, a commit, a remote branch)Goes back to the previous branch or commit.
Creating, renaming and deleting a local branchThe branch exists again, goes back to its old name or stops existing.
Creating and deleting a local tagThe tag stops existing or comes back.
Stashing (everything, one file)The changes go back to the working directory and the stash leaves the list.
Snapshot, staged-only stash, stash of a hunk or of linesThe stash leaves the list and the files go back to how they were (copy made beforehand).
Deleting a stashThe stash goes back to the list.
Discarding changes (file, hunk, lines, all) and deleting a fileThe files come back from the copy made before the discard, and the staging area goes back to how it was.
Apply stash (including when it conflicts)The files the stash changed go back to how they were, the ones it created are deleted, and the stash stays in the list.
Apply patch… (from a file), applying a patch from the clipboard, applying part of a stashThe files the operation changed come back from the copy. With the file patch and the stash part, the files the operation created are deleted.
Restoring a file from a commit, .gitignore templates, restoring from the local historyThe files the operation changed come back from the copy.
With a stopped operation or conflicted files: Save and mark resolved, Use the version…, deleting the conflicted file, Start over and Reopen (conflict editor), Resolve several…, staging a conflicted file and discardsThe file goes back to how it was before the step, on disk and in staging, with the conflict back when there was one. See "Stopped operations", below.
Stack feature/b on…, Remove feature/b from the stack and Record the stack in VersoraThe stack configuration goes back to how it was (the branches don't change). See Stacks.
Going back to a named point, going back to a reflog pointThe repository goes back to the state before going back.
Team commands (.versora.yml)According to the command's undo: (hard, soft, mixed or off). See Team rules.

Each open repository (and each worktree) has its own stack, with the 40 most recent operations.

What Ctrl+Z doesn't undo

WhatWhy, and what to use
Stage and unstage (except staging a conflicted file, above)They don't touch references. Use the opposite action (Staging).
Push, deleting a branch or tag on the remote, anything on the serverUndo only tracks what's local. A force push back is your decision (Force push).
FetchIt only updates the remote branches.
Apply and remove (pop) of a stashPop mixes the stash with your files: there's no safe way to give it back. Prefer Apply stash, which goes in.
Edit stash message…It doesn't go into undo. Edit it again.
Abort of a stopped operationAbort itself already takes the repository back to before the operation: there's nothing to undo.
The steps taken during a stopped operation, after it finishesWhen the operation finishes, they leave the history: if it was finished, Ctrl+Z undoes the whole operation at once. See "Stopped operations", below.
A rebase, cherry-pick or revert that stopped and that the app didn't start in this session (from the terminal, or before the app was closed)The app doesn't have the snapshot from before the operation. Once it's finished, use the reflog.
Marking, renaming and deleting named pointsThey don't change the repository. Deleting a point can't be undone.
Putting files on and taking them off the "don't commit" list, deleting the local historyThey aren't git operations.
What was done outside the app (terminal, another program)The app didn't take a snapshot. Use the reflog or the local history.

Stopped operations

When a merge, rebase, cherry-pick or revert stops midway (a conflict, a hook that refused, a stop to edit in the interactive rebase), the repository is left in a provisional state until you continue or abort. Ctrl+Z handles that period in two phases.

During the stop, the steps that only touch files go into undo: resolving a file in the conflict editor (Save and mark resolved, Use the version…, deleting the file), Start over, Reopen, Resolve several…, staging a conflicted file and discards. Each Ctrl+Z goes back one step: the file goes back to how it was, on disk and in staging, with the conflict back. These steps can also be redone with Ctrl+Shift+Z. What was done before the stop can't be undone while it lasts ("A merge is in progress…", below).

When the operation finishes, these steps leave the history, because the state in which they applied no longer exists:

  • Finished (with Continue, with the commit, with Finish the merge without hooks, even from the terminal): the whole operation goes in their place. One Ctrl+Z takes the branch and the files back to before the merge, rebase, cherry-pick or revert, always as a hard reset (that's why it refuses if there are uncommitted changes). On the undo button, it shows up with the name of the operation the app started; a merge started outside the app shows up as "Finished merge" (with Continue) or "Merge finished without hooks".
  • Aborted: nothing goes in. Abort has already taken the repository back to before the operation.

To go in as a whole, the operation must have been started by the app, with it open ever since (the snapshot from before lives in the app's memory). The exception is a merge finished in the app (with Continue, with the commit or with Finish the merge without hooks): it goes in even if it was started from the terminal.

Caution

The undo stack lives while the app is open. When you close Versora, it's lost. For a state that needs to survive, mark a named point.

What Versora does in git

Undoing means taking each reference back to the snapshot from before, in this order:

bash
git update-ref refs/heads/feature/login <old-sha>         # branches that aren't the current one
git update-ref -d refs/heads/feature/novo                 # branch created by the operation
git update-ref refs/tags/v1.2.0 <old-object>              # tags
git checkout main --                                      # if HEAD was on another branch
git reset --soft <old-sha>                                # the current branch (--soft, --mixed or --hard)
git stash store -m "<message>" <stash-sha>                # a deleted stash goes back to the list
git stash pop --index                                     # a stash created by the operation: the changes come back
git restore --source=<copy> --worktree -- <files>         # discarded files come back from the copy
git restore --source=<tree> --staged -- <files>           # and the staging area goes back to how it was

Backup copies of the files

Before operations that destroy uncommitted changes (discard, hard reset, deleting a file, restoring a version, partial stashes), the app keeps the files in a loose commit, with the message "versora: restore point" (in the interface language), pointed to by a reference of its own:

  • The name is refs/versora/undo/<moment>. These references don't show up as branches, don't go with the push and keep git gc from deleting the copy.
  • When the operation says which files it's going to touch, only those are copied (much faster in large repositories). Files ignored by .gitignore aren't included in the copy.
  • With a stopped operation or conflicted files, the copy is made file by file, because the regular copy (a git tree) doesn't keep the conflicted versions in the staging area. It takes the staging entries with the conflict stages, the content on disk byte for byte and the operation's state files (MERGE_HEAD, MERGE_MSG…). The loose commit's message is "versora: restore point (stopped operation)".
  • The app keeps the 20 most recent copies per repository and deletes the older ones.
  • The copies stay in the repository even after closing the app. Without the Ctrl+Z stack, you can use them from the terminal as a last resort:
bash
git for-each-ref --sort=-refname refs/versora/undo          # the copies, from most recent to oldest
git show --stat refs/versora/undo/1764190000000             # what a copy has
git restore --source=refs/versora/undo/1764190000000 -- src/app.ts

How to undo

Redo with Ctrl+Shift+Z (next section).

Caveats and messages

Before touching anything, the app checks whether the repository is as the operation left it. If it isn't, it refuses instead of overwriting what it doesn't know. The refused operation goes back on the stack: fix the reason and try again.

  • "A merge is in progress. Finish or abort it (in the changes panel) before undoing." (or rebase, cherry-pick, revert): the step to undo is from before the stop. The steps taken during it are undone normally; to go beyond them, finish or abort the operation. See Operations stopped midway.
  • "The operation this was done in is no longer as it was (it was finished, aborted or restarted): this step can no longer be undone.", followed by "That step was removed from the undo history; press Ctrl+Z again to go on with the previous one.": a step taken during a stopped operation lost its effect because the operation changed outside the app (from the terminal, for example). The step leaves the stack; the next Ctrl+Z goes on to the previous one.
  • "A bisect is in progress. End it (in the bisect bar, below the toolbar) before undoing.": see Bisect.
  • "The repository has changed since this operation, so it isn't safe to undo it automatically.": some branch, tag, stash or HEAD changed without going through undo, for example a commit from the terminal, a stash pop, a fetch that brought new tags or another git program. Use the reflog.
  • "There are uncommitted changes. Stash or commit them before undoing this operation.": undoing a merge, rebase, checkout or hard reset replaces the files in the working directory, and that would overwrite your changes to tracked files. Untracked files don't block it.
  • "The files were changed again after this operation. Undoing now would overwrite those changes.": you edited again a file that undo was going to restore from the copy. To recover the copy's version without losing the new one, use the local history or the commands in "Backup copies", above.
  • While the app is running an operation (the busy indicator on the bar), Ctrl+Z and the undo and redo buttons do nothing. Wait for the operation to finish.
  • The keys can be changed in the keymap ("Undo the last operation" and "Redo"). See Shortcuts.
  • For team commands, .versora.yml sets how each command is undone (undo: and snapshot: true). See Team rules and Custom commands.

See also

Redoes the operation you just undid.

Where to find it

  • Shortcut: Ctrl+Shift+Z or Ctrl+Y, outside a text field.
  • Toolbar: the redo button, next to the undo one, with the tooltip "Redo: Commit "Fix login" (Ctrl+Shift+Z)" (or "Nothing to redo").
  • Palette: "Redo", with the detail "Redoes: …".
  • Timeline: the undone operations show up at the top, dashed, with Redo up to here.

Step by step

  1. After a Ctrl+Z, press Ctrl+Shift+Z.
  2. The indicator shows "Redoing…" and the notice confirms: "Redone: Commit "Fix login"".

What Versora does in git

Redoing takes the references back to the snapshot from after the operation, with the same commands as undo. The files are left to git itself: when you redo a commit, for example, what had gone back to the stage goes back into the redone commit.

Caveats and messages

  • A new operation erases what was waiting to be redone: if you undid a commit and then did a checkout, there's no way to redo the commit with Ctrl+Shift+Z anymore.
  • Undoing an operation that only discarded files (without changing branches) leaves nothing to redo. To discard again, discard again. The exception is the steps taken during a stopped operation (conflict resolutions, discards): those can be redone.
  • "Nothing to redo.": the redo stack is empty.
  • The same refusals as undo apply here.

See also