Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git reset: undo and travel back in time

git reset lets you undo commits, unstage files or go back to a previous state. Three modes (soft, mixed, hard) for three levels of control.

Powerful

What is git reset?

git reset moves the HEAD pointer to a previous commit. Depending on the mode chosen, it can also modify the staging area and the working directory.

It's like a time machine: you choose how far back to go and what you keep from your journey.

Warning: on a shared branch, prefer git revert which doesn't rewrite history.

The 3 reset modes

git reset --soft HEAD~1

Keeps changes staged

git reset HEAD~1

Mixed (default): moves to working directory

git reset --hard HEAD~1

Deletes everything permanently

Git reset in practice

Undo a commit or unstage files.

Soft reset (keep staging)

Hard and mixed reset

Comparing reset modes

--soft

The commit is undone but changes remain in the staging area. Ideal for redoing a commit with a better message.

Safe

--mixed

The commit is undone and changes go back to the working directory. This is the default mode.

Safe

--hard

The commit is undone and changes are deleted. Your code returns to exactly the target commit.

Destructive

Common mistakes with git reset

Reset --hard on a shared branch

If other developers have already pulled your commits, a reset will desynchronize everyone. Use git revert instead.

Confusing reset and checkout

reset moves HEAD (and potentially the staging/working directory). checkout switches branches or restores files. These are different operations.

Forgetting to check git status first

A hard reset also deletes uncommitted changes. Always check what you have in progress before resetting.

Part of the Undo Changes in Git guide

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about git reset

Master reset with GitQuest

Learn to navigate Git history and undo mistakes with confidence.

Start the investigations