# Git Reset

URL: https://softwaredictionary.org/terms/git-reset
Category: Version Control
Last updated: 2026-09-30

In short: Git reset is a Git command that moves the current branch back to an earlier commit and, depending on its mode, also resets the staging area and your files.

## What is git reset?

`git reset` rewinds the current branch so it points at a different commit, usually an earlier one, which removes the later commits from that branch's history. It is mainly used to undo local commits that haven't been shared yet, or to unstage files. For example, `git reset HEAD~1` moves the branch back one commit, where `HEAD~1` means 'the commit before the current one'.

Three modes decide what happens to the changes from the commits you undo. `--soft` moves only the branch, leaving those changes staged and ready to commit again; `--mixed`, the default, also clears them from the staging area but keeps them in your working files; and `--hard` resets the staging area and working files as well, discarding every uncommitted change. Given a file path instead of a commit, as in `git reset <file>`, the command simply unstages that file.

Reset is like moving a bookmark back to an earlier page of a diary, where the mode decides whether the pages written since are kept as loose notes or thrown away. Commits you reset away are not destroyed at once: `git reflog` lists where the branch pointed before, so you can usually jump back with `git reset --hard <old-hash>` for weeks afterward. Uncommitted edits wiped out by `--hard`, however, were never saved in Git and cannot be recovered that way.

Git reset is most often confused with `git revert`. Reset rewrites history by moving the branch pointer, which is fine for local commits but causes trouble on a branch others have pulled, because their copies still contain the commits you removed. Revert leaves history intact and adds a new commit that undoes an old one, so it is the safe way to undo shared commits. Reset is also different from `git restore`, which only changes files and never moves a branch.

## Key takeaways

- `git reset <commit>` moves the current branch to another commit, removing later commits from it.
- `--soft` keeps the undone changes staged, `--mixed` (the default) keeps them unstaged, and `--hard` discards them.
- `git reset <file>` unstages a file without changing its contents.
- Reset rewrites history, so use it for local commits and `git revert` for shared ones.
- `git reflog` can help you recover commits after a mistaken reset.

## Example: Undoing commits with the three reset modes

```bash
# Undo the last commit but keep its changes staged
git reset --soft HEAD~1

# Undo the last commit and unstage its changes (the default, --mixed)
git reset HEAD~1

# Throw away the last commit AND all uncommitted changes (careful!)
git reset --hard HEAD~1

# Unstage a file without touching its contents
git reset src/app.ts

# Made a mistake? Find the previous position and go back to it
git reflog
git reset --hard HEAD@{1}
```

## Frequently asked questions

**What is the difference between git reset and git revert?**

`git reset` moves a branch back to an earlier commit and drops the later ones from it, so it suits local work that hasn't been pushed. `git revert` creates a new commit that undoes an earlier one and keeps history intact, so it is safe on shared branches.

**What is the difference between git reset --soft, --mixed, and --hard?**

All three move the branch to the target commit. `--soft` keeps the undone changes staged, `--mixed` keeps them as unstaged edits, and `--hard` removes them from both the staging area and the working directory.

**Can I undo a git reset --hard?**

Committed work can usually be recovered: run `git reflog`, find the hash the branch pointed to before the reset, and reset back to it. Uncommitted changes discarded by `--hard` were never saved by Git and generally cannot be recovered.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
