git reset --hard explained (soft vs mixed vs hard) - Rocketeers

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com) 

 On this page

 Knowledge
---------

git reset --hard explained (soft vs mixed vs hard)
==================================================

### [\#Development](https://rocketee.rs/index.php/development)

git reset moves your branch to another commit. The --soft, --mixed and --hard flags decide what happens to your staged and working changes, and --hard is the one that actually throws work away.

 Published by [Mark van Eijk](https://rocketee.rs/index.php/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [What git reset does](#content-what-git-reset-does)
2. [Undo the last commit, keep the work](#content-undo-the-last-commit-keep-the-work)
3. [Discard everything with --hard](#content-discard-everything-with---hard)
4. [Recovering after a --hard reset](#content-recovering-after-a---hard-reset)

[\#](#content-what-git-reset-does "Permalink")What git reset does
-----------------------------------------------------------------

`git reset` moves the current branch tip to a commit you choose. The flag controls how far the reset reaches:

- `--soft`: move the branch, **keep** everything staged.
- `--mixed` (the default): move the branch, unstage changes, keep them in your working directory.
- `--hard`: move the branch and **discard** all staged and working-directory changes.

[\#](#content-undo-the-last-commit-keep-the-work "Permalink")Undo the last commit, keep the work
------------------------------------------------------------------------------------------------

To undo your most recent commit but keep the changes so you can re-commit them, use `--soft` or the default `--mixed`:

 ```
git reset --soft HEAD~1   # commit undone, changes still staged
git reset HEAD~1          # commit undone, changes unstaged but present

```

[\#](#content-discard-everything-with---hard "Permalink")Discard everything with --hard
---------------------------------------------------------------------------------------

`--hard` resets the branch and wipes uncommitted changes. Use it when you genuinely want to throw work away:

 ```
git reset --hard HEAD     # discard all uncommitted changes
git reset --hard HEAD~1   # delete the last commit and its changes

```

A common use is forcing your local branch to match the remote exactly:

 ```
git fetch origin
git reset --hard origin/main

```

This is destructive. Anything not committed is gone. If you only want to clean up *untracked* files (not reset tracked ones), use [git clean](/git-remove-untracked-files) instead.

[\#](#content-recovering-after-a---hard-reset "Permalink")Recovering after a --hard reset
-----------------------------------------------------------------------------------------

If you reset away a commit you actually needed, it is usually still findable for a while. `git reflog` records where `HEAD` has been:

 ```
git reflog
git reset --hard 

```

Note that `reflog` only recovers committed work. Changes that were never committed and got discarded by `--hard` cannot be recovered. When in doubt, [stash](/git-stash-pop) your changes instead of resetting.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Development](https://rocketee.rs/index.php/development)

- [Install PHP memcached extension on macOS](https://rocketee.rs/index.php/install-php-memcached-extension-on-macos)
- [How to delete a local (and remote) Git branch](https://rocketee.rs/index.php/git-delete-local-branch)
- [Fix: Cannot connect to the Docker daemon at unix:///var/run/docker.sock](https://rocketee.rs/index.php/cannot-connect-to-docker-daemon)
- [git stash pop vs apply: save and restore changes](https://rocketee.rs/index.php/git-stash-pop)
- [How to clean up Docker with prune (images, volumes, system)](https://rocketee.rs/index.php/docker-prune)
- [What port does SSH use (and how to change it)](https://rocketee.rs/index.php/ssh-port)

 [View all 12 articles →](https://rocketee.rs/index.php/development)
