git reset --soft vs --mixed vs --hard: What Each One Moves, with Real git status and git log Output, and How to Undo a Reset with reflog

TL;DR

  • git reset <commit> moves the current branch to <commit>. The mode decides what else changes: --soft leaves the index and the files alone, --mixed (the default) also resets the index, --hard also overwrites the tracked files in the working tree.
  • --soft HEAD~1 turns the last commit back into staged changes. --mixed HEAD~1 turns it into unstaged changes. --hard HEAD~1 deletes it from the branch and discards the changes.
  • Uncommitted tracked edits cannot be recovered after --hard. Committed work can: git reflog still listed the commit I had "lost", and git reset --hard HEAD@{1} brought it back.
  • Untracked files survive every mode. In my run scratch.txt was still there after --hard.
  • Shared branch? Use git revert, not reset. Reset rewrites history that others may have pulled.
  • Not your exact case? If you want to change only the last commit message, see the amend and reset chapters of the Git and GitHub blueprint course companion.

What git reset moves in each mode

Table of Content

  1. The three areas reset works on
  2. git reset --soft
  3. git reset --mixed
  4. git reset --hard and getting the commit back
  5. What broke when I ran this
  6. Reset, revert or restore?

This is the written version of my Day 6 DevOps course video. Every command below I ran on 2026-11-30 with Git 2.43.0 in a fresh repository holding three commits, add feature 1 to add feature 3, each appending one line to app.txt. The git reset documentation is the reference; the Pro Git chapter Reset Demystified explains the same thing with the three-tree model I use here.

The three areas reset works on

Git keeps your work in three places: the commit history (HEAD), the index (what is staged for the next commit) and the working tree (the files on disk). Every git reset first moves HEAD (and the branch it points to). The mode then decides how far the change travels: nothing more (--soft), to the index (--mixed), or to the index and the working tree (--hard).

ModeHEAD / branchIndex (staged)Working treeTypical use
--softmovedkeptkeptredo the last commit, squash locally
--mixed (default)movedresetkeptunstage everything, re-pick what to commit
--hardmovedresettracked files overwrittenthrow the work away

git reset --soft

Starting point:

1$ git log --oneline
216292b7 add feature 3
3abcc1ed add feature 2
4d9e0fc7 add feature 1

Soft reset one commit back, then look at what is left:

1$ git reset --soft HEAD~1
2$ git status --short
3M  app.txt
4$ git log --oneline
5abcc1ed add feature 2
6d9e0fc7 add feature 1
7$ git diff --cached --stat
8 app.txt | 1 +
9 1 file changed, 1 insertion(+)

The commit is gone from the branch, but M app.txt (a letter in the first column) means the change is staged. One git commit would recreate it. This is the mode I use to combine the last few commits into one, or to fix a commit message with new content: git reset --soft HEAD~3 && git commit.

git reset --mixed

I put the commit back with git commit -C ORIG_HEAD (Git writes the previous HEAD to ORIG_HEAD before a reset), then ran reset with no mode:

1$ git reset HEAD~1
2Unstaged changes after reset:
3M	app.txt
4$ git status --short
5 M app.txt
6$ git log --oneline
7abcc1ed add feature 2
8d9e0fc7 add feature 1

Same history as the soft reset, but now the status line starts with a space: M app.txt is modified and not staged. The file on disk still contains feature 3. That is why this is the default: it is the safe "undo the commit and unstage it" mode.

git reset --hard and getting the commit back

Now the dangerous one. I re-committed, then made an uncommitted edit to app.txt and created an untracked scratch.txt:

 1$ git status --short
 2 M app.txt
 3?? scratch.txt
 4$ git reset --hard HEAD~1
 5HEAD is now at abcc1ed add feature 2
 6$ git status --short
 7?? scratch.txt
 8$ cat app.txt
 9feature 1
10feature 2

Three things happened at once: the commit add feature 3 left the branch, my uncommitted line tracked edit not committed vanished, and scratch.txt survived because Git does not track it. The edit is gone for good: it was never committed, so no reflog entry exists for it.

The commit is different. The git reflog documentation describes the log of where HEAD has been, and it still had the commit:

 1$ git reflog
 2abcc1ed HEAD@{0}: reset: moving to HEAD~1
 316292b7 HEAD@{1}: commit: add feature 3
 4abcc1ed HEAD@{2}: reset: moving to HEAD~1
 5$ git reset --hard HEAD@{1}
 6HEAD is now at 16292b7 add feature 3
 7$ cat app.txt
 8feature 1
 9feature 2
10feature 3

git reset --hard ORIG_HEAD right after a reset does the same in one step, which I also tried. Reflog entries are kept for a limited time (90 days by default for reachable entries, 30 days for unreachable ones, per the git reflog documentation), so recover quickly.

What broke when I ran this

  • My first demo was confusing. I ran git add -A before a hard reset, which also staged an untracked file. After the reset that file was deleted, because it had become tracked. If you want to show that untracked files survive, do not stage them.
  • git reset --keep refused to run. With a dirty app.txt I tried git reset --keep HEAD~1 and got error: Entry 'app.txt' not uptodate. Cannot merge. followed by fatal: Could not reset index file to revision 'HEAD~1'. (exit status 128). --keep is the cautious hard reset, and it stops when a file you changed also differs in the target commit. Commit or stash first.
  • Counting reflog entries. After three resets my reflog had six lines for the same commit, so HEAD@{1} was not the entry I assumed on the first try. Read the reflog before you type the number.
  • The reset itself is instant. I timed each mode around the command: --soft, --mixed and --hard each took 5 ms on this tiny repository, and git count-objects -vH reported 9 loose objects at 36.00 KiB, while git reflog took 4 ms and git status --short took 10 ms, so there is no cost reason to avoid it, only a safety reason.

Reset, revert or restore?

GoalCommandRewrites history?
Undo a local, unpushed commitgit reset --soft HEAD~1yes
Undo a commit already pushed to a shared branchgit revertno, adds a new commit
Discard changes in one filegit restore <file>no
Throw away everything uncommittedgit reset --hardno commits lost, files lost

My rule: reset only commits that exist on my machine alone. For anything pushed, I revert. After a reset of a pushed branch you would need a force push, which rewrites the branch for everyone else. If the remote rejects your push because of authentication instead, that is a different problem, covered in the personal access token fix; and if you want to clean up branches after the work is merged, read deleting merged branches.

Did this save you a debugging session? Stay in the loop -