History
Reset (soft, mixed, hard)
4 min read
Reset moves the current branch to another commit. The commits that were above that point leave the branch. What happens to their changes depends on the mode:
| Mode | Menu label | The branch | The staging area | The files |
|---|---|---|---|---|
| Soft | "Soft — keep all changes staged" | Moves to the chosen commit | Keeps the changes from the commits that left (and what was already staged) | Don't change |
| Mixed | "Mixed — keep the files, clear the stage" | Moves to the chosen commit | Becomes the same as the chosen commit (everything is unstaged) | Don't change: the changes stay unstaged |
| Hard | "Hard — discard all changes…" | Moves to the chosen commit | Becomes the same as the chosen commit | Go back to the chosen commit: uncommitted changes are discarded |
Common uses:
- Soft: redoing the last commits another way. The last three commits become a single set of staged changes, and you make a new commit with everything.
- Mixed: undoing the last commits and choosing again what goes into staging.
- Hard: throwing away the last commits and the local changes, taking the branch back to a known point.
- A commit's menu › Reset feature/login to this commit › Soft — keep all changes staged, Mixed — keep the files, clear the stage or Hard — discard all changes….
- A branch's menu (local or remote) › the same submenu, for the commit at the tip of that branch.
For example, in the menu of
origin/feature/login, "Reset feature/login to this commit" takes the current branch to the tip of the remote.
Reset always moves the current branch (its name shows up in the item). In detached HEAD, the item says "Reset HEAD to this commit".
Example: the last three commits of feature/login should have been one.
- In the graph, right-click the commit that will be at the top after the reset, for example
b2c3d4e Validate email on login(the fourth from the top). - Open Reset feature/login to this commit and choose Soft — keep all changes staged. Soft and mixed run right away, without confirmation ("Resetting (soft)…").
- The branch now points to
b2c3d4e, and the changes from the three commits that left are staged. - Write the message in the commit box and commit (see The commit box).
For Hard mode, Versora asks for confirmation first: the "Hard reset" dialog asks "Move feature/login to b2c3d4e and DISCARD all uncommitted changes? You can undo it right after (Ctrl+Z)." and confirms with Discard and reset.
| Option | What it does | Default |
|---|---|---|
| Soft | Only moves the branch | — |
| Mixed | Moves the branch and clears the staging area | — |
| Hard | Moves the branch, clears the staging area and restores the files (with confirmation) | — |
There's no default mode: you choose it in the submenu.
git reset --soft b2c3d4e
git reset --mixed b2c3d4e
git reset --hard b2c3d4e
Before a hard reset, Versora keeps a copy of the uncommitted changes in a commit pointed to by an
internal reference (refs/versora/undo/*, the 20 most recent per repository). These references
don't show up as branches, don't go with the push and keep git from deleting the copy. That's what
lets Ctrl+Z bring the files back.
The commits that left the branch aren't deleted: they remain in the repository and show up in the reflog until git cleans them up.
Ctrl+Z ("Undo: Soft reset", "Undo: Mixed reset" or "Undo: Hard reset") takes the branch back to the previous commit, in the same mode:
- Soft and mixed: the branch goes back to the previous commit, without touching the files in the working directory.
- Hard: the branch goes back, and the uncommitted changes the reset discarded come back from the backup copy.
Undo refuses when it isn't safe:
- "The files were changed again after this operation. Undoing now would overwrite those changes.": you edited files after the hard reset. Stash or commit them first.
- "There are uncommitted changes. Stash or commit them before undoing this operation."
- "The repository has changed since this operation, so it isn't safe to undo it automatically.": there was another commit, checkout or branch change afterwards. Use the reflog.
- Reset rewrites the branch: if the commits that left were already on the remote, the next push has to be forced, and the force push deletes those commits from the remote. On a shared branch, prefer revert.
- "Invalid reset mode: …": an internal error; it shouldn't show up in normal use.
- A hard reset also restores changed tracked files; untracked files aren't touched by
git reset --hard.
No preference or policy key changes reset.
- Undo and redo
- Reflog: the "Reset to here" button does a hard reset of the branch to an old point.
- Branches and remotes: when checking out a remote branch that diverged from the local one, Versora offers to reset the local branch to the remote.
- Commit surgery: "Uncommit…" removes a commit from the middle of the branch and brings its changes back to the stage.
- Discard changes