git reset: move the branch pointer back

Updated July 31, 2026

git reset moves the pointer of the current branch to another commit, and the modes --soft, --mixed and --hard decide what happens to the index and to your files. A branch is a pointer to a commit, so "undoing a commit" here means moving that pointer, not deleting anything from the archive.

$ git log --oneline
ac8aecb budget draft
435eda7 added the hiring section
00ef0ff first draft of the report

$ git reset --soft HEAD~1
$ git status --short
M  report.txt

--soft removes the commit and nothing else. Its changes stay in the index in full, and the next git commit builds a new snapshot out of them. That is how you squash two small commits into one or rewrite a bad message.

--mixed is what you get when you do not name a mode. The commit is gone, the changes are still in the files, but they are taken out of the index:

$ git reset HEAD~1
Unstaged changes after reset:
M	report.txt

--hard leaves nothing: the commit is gone and the working directory is brought to the new position.

$ git reset --hard HEAD~1
HEAD is now at 435eda7 added the hiring section

This is the only mode that really loses work. The commit you dropped is still findable by hash in git reflog, but edits that never reached a commit, the index or git stash are findable nowhere.

Reset fits while the commits live on your machine only: you rewrite the history and nobody notices. Once the branch is on the server and somebody has pulled it, moving the pointer puts you out of step with their history, and that is a job for git revert.

Common mistakes

git reset with a file name is a different operation. It does not move the branch pointer; it takes the file out of the index, the same thing git restore --staged does. One name, two roles: since version 2.23, reach for git restore when you mean files.

HEAD~1 means "one commit back", not "the last commit". git reset --hard HEAD leaves the history untouched and quietly throws away every unsaved edit in your files. When you are unsure what is about to go, look at git status and git diff first.

Where this is in the book

The three reset modes and the choice between reset and revert are covered in chapter 8.

Chapter 8. First aid: when something goes wrong

To practise it by hand, open the Sandbox: a real terminal with git and step checks.