Git reset is a powerful command that lets you undo mistakes and reconfigure your commit history. Whether you need to unstage changes, throw away commits, or reorganize your work in progress, Git reset gives you the flexibility to manage your repository state exactly as you want it.
Hard Reset (Discard Changes)
The git reset --hard HEAD command completely discards all uncommitted changes and resets your working directory to match the last commit. Use this with caution as it permanently deletes any unstaged changes.
$ git reset --hard HEAD
Try it Yourself โ
Soft Reset (Keep Changes)
Use git reset --soft HEAD to undo a commit while keeping all changes staged. This is useful when you want to amend a commit message or reorganize staged changes before committing.
$ git reset --soft HEAD
Try it Yourself โ
Mixed Reset (Unstage Changes)
The git reset --mixed HEAD command (the default) unstages your changes while keeping them in your working directory. This is the safest option for undoing staged changes without losing your modifications.
$ git reset --mixed HEAD
Try it Yourself โ