Skip to content
Versora

Manual

Undo

How to recover lost work

7 min read

On this page

It can almost always be recovered. What changes is where the copy is: in the Ctrl+Z stack (while the app is open), in a named point, in the local file history, in the stash list or in git's reflog. This page points to the right feature for each situation. The details of each one are on the pages indicated.

Caution

First of all, stop. Each new operation in the repository can erase what was waiting to be redone and make Ctrl+Z refuse ("The repository has changed since this operation…"). Recover first, continue the work afterwards.

SituationUse firstIf that doesn't work
I just did something wrong in the appCtrl+ZReflog
I undid too muchCtrl+Shift+Z or Redo up to here in the timeline—
I want to go back several stepsTimeline › Go back to hereNamed point
I deleted a branchCtrl+ZNamed point, reflog
I did a hard resetCtrl+Z (done in the app)Reflog (commits) and local history (files)
The editor overwrote my fileLocal history—
I deleted a file outside the appLocal history › Deleted only—
I discarded changesCtrl+Z (done in the app)Local history
I lost a stashCtrl+Z (deletion done in the app)Named point, git fsck
The rebase went wrongAbort (stopped) or Ctrl+Z (finished in the app)Reflog
I finished a merge with conflicts and regretted itCtrl+Z (finished in the app)Reflog
I closed the app and Ctrl+Z is goneNamed point, local historyReflog, refs/versora/undo/* copies

I just did something wrong in the app

Press Ctrl+Z (outside a text field). The tooltip on the undo button, on the toolbar, says which operation will be undone. If the app refuses, the message explains why and what to do; the refusals are in Undo and redo. To know beforehand what Ctrl+Z reaches (and what it doesn't, such as a stash pop or a push), see the same page.

I undid too much

Ctrl+Shift+Z redoes one operation at a time. To redo several, open the timeline (Alt+Z), click the dashed operation up to where you want to go and use Redo up to here. Redo before any new operation: it erases what was waiting to be redone.

I want to go back several steps

In the timeline, click the oldest operation you want to undo and read the Go back to here plan: each step, the files that change and the final state. If you had marked a named point beforehand, Go back to this point takes everything to the point's state at once.

I deleted a branch

  • From the app, in this session: Ctrl+Z ("Delete branch feature/login") recreates the branch on the same commit.
  • There was a named point from before the deletion: Go back to this point recreates the branches that existed at the point. See Timeline and named points.
  • From the terminal, or after closing the app: open the reflog (the clock icon on the toolbar, "Reflog — where HEAD has been (recover commits)"), find the branch's last commit and create a branch on it.
  • On the remote: Ctrl+Z doesn't reach the server. If you still have the local branch, push it again (Push).

I did a hard reset

  • From the app, in this session: Ctrl+Z ("Hard reset") takes the branch back to the previous commit and gives back the uncommitted changes the reset discarded: the app kept a copy beforehand. See Reset.
  • From the terminal: the commits come back through the reflog (the point before the reset). The uncommitted changes aren't in the reflog: look for them in the local history, which keeps the files with uncommitted changes every time they changed on disk with the tab open. Use By moment and Take all files back to this moment….

The editor overwrote my file

Open the file's local history: right-click it › Local history of this file… (or Alt+H). Compare the versions With the current file and use Restore this version…. The current version is also kept, and Ctrl+Z undoes the restore.

The local history only has versions of files that had uncommitted changes and that the app saw change (the repository open in a tab, the history turned on). If the file was the same as the commit, the content is in git itself: discard the change (Discard changes) or see the file history.

I deleted a file outside the app

In the local history, By file mode, check Deleted only. The deleted files show up with the deleted badge; choose the last changed version before the deletion and click Restore this version….

If the file was tracked and you had no changes in it, it's in git: the changes panel shows the deletion, and discarding it brings the file back.

I discarded changes

  • From the app (discarding a file, hunk, lines or everything): Ctrl+Z ("Discard changes") gives the files back from the copy the app made beforehand. If you edited the file again afterwards, Ctrl+Z refuses so as not to overwrite it; use the local history.
  • From the terminal (git checkout -- ., git restore, git clean): the local history has the versions the app saw.

I lost a stash

  • I deleted it from the app, in this session: Ctrl+Z ("Delete stash") puts the stash back in the list.
  • The pop ran into a conflict: git keeps the stash in the list; it didn't disappear. See Stash.
  • The autostash didn't come back cleanly: the notice has Show the stash. See Autostash.
  • There was a named point from before: the point keeps the commits of the stashes from that moment, and Go back to this point puts those stashes back in the list.
  • I deleted it from the terminal or after closing the app: the stash's commit still exists until git's next cleanup. From the terminal, find it and put it back in the list:
bash
git fsck --unreachable | grep commit                 # loose commits; stash ones have the message "On main: …" or "WIP on main: …"
git show --stat <sha>                                  # check the content
git stash store -m "Recovered" <sha>

The official git stash (opens another site) documentation explains the procedure in detail.

The rebase went wrong

  • It's still stopped (the Rebase in progress bar): Abort undoes the whole rebase. See Operations stopped midway.
  • It was started from the app, in this session, and finished (without stopping, or after stopping at a conflict and you continuing until the end): Ctrl+Z ("Rebase onto main") takes the branch back to the history from before the whole rebase.
  • It was started from the terminal, or the app was closed midway: Ctrl+Z doesn't reach it. In HEAD's reflog, the point before the rebase is the entry right before (older than) the "rebase (start)" one. Create a branch on it or reset the branch to it (Reset).
  • Before a big rebase, mark a named point: going back to it is one click.

I finished a merge with conflicts and regretted it

  • Finished in the app, in this session (with Continue, through the commit box or with Finish the merge without hooks): Ctrl+Z undoes the whole merge. The branch goes back to the commit before the merge and so do the files; the conflict resolutions go with it. First, stash or commit any uncommitted changes, or undo refuses.
  • Finished from the terminal, or the app was closed afterwards: Ctrl+Z doesn't reach it (unless the app started the merge and is still open). The merge commit's first parent is the commit the branch was on before: reset the branch to it, or find the point in the reflog.
  • If the merge has already gone to the remote, prefer a revert to rewriting the history.

I committed to the wrong branch, or committed what I shouldn't have

  • Ctrl+Z undoes the commit and gives the changes back to the stage: nothing is lost. Switch branches and commit again, or unstage what shouldn't go.
  • So that a local file doesn't go into the commit by mistake again, put it on the "don't commit" list.
  • If the commit has already gone to the remote, see Revert or the force push in Force push.

I closed the app and Ctrl+Z is gone

The undo stack lives only while the app is open. What remains afterwards:

  1. Named points: they're in the timeline again when you open the repository.
  2. Local history: the file versions, up to the days and space limits.
  3. Reflog: every place HEAD and the branches have been.
  4. The undo backup copies, in refs/versora/undo/* (the 20 most recent): each one has the files an operation discarded. How to use them from the terminal is in Undo and redo.

See also