Last Updated: January 3, 2026
When it comes to managing your Git repository, knowing how to reset your changes can be a lifesaver.
You might find yourself in situations where you realize that your latest commits, staged changes, or even edits in your working directory are not quite what you intended.
This is where Git's reset command shines, particularly through its three main modes: soft, mixed, and hard.
Understanding these modes will empower you to manipulate your commit history and working state confidently, without fear of irreversible mistakes.
Before diving into the specifics of each reset mode, let's clarify what the git reset command does at a high level. Essentially, it changes the current branch’s HEAD pointer to a specified state. Depending on the mode you choose, it also affects the staging area and the working directory.
Here’s a simple overview of how the three modes differ:
Understanding these differences will help you choose the right mode for your situation.
The soft reset is often your first choice when you want to undo commits while keeping your changes intact for further editing or staging.
A soft reset moves the HEAD to a specified commit, making it the new current commit. However, it leaves all your changes in the staging area, which means you can easily modify them or create new commits.
Imagine you’ve made several commits, but you realize that the last two commits were not what you wanted. You want to merge those changes into a single commit.
First, check your commit history to determine how many commits you want to undo:
Suppose you see the following:
You can use a soft reset to move back to the initial commit:
After running this command, your changes from both the "Add new feature" and "Fix typo in documentation" commits will be staged, allowing you to modify them as you see fit.
The mixed reset is the default mode of git reset and is particularly useful when you want to unstage changes while keeping your working directory intact.
A mixed reset will move the HEAD pointer and reset the staging area to match a specified commit, but it will not alter your working directory. Your changes will remain in the working directory but will no longer be staged.
Suppose you’ve added several files to the staging area but realize that you only want to commit specific changes. Here’s how you can use a mixed reset:
Stage some files:
Use git status to confirm they are staged:
If you decide to unstage file2.txt, run:
After this, file1.txt and file3.txt will remain staged, but file2.txt will be unstaged and left in your working directory.
The hard reset is the most aggressive option available and should be used with caution. It’s handy when you want to completely discard changes made since a specified commit.
A hard reset moves the HEAD pointer, resets the staging area, and resets the working directory to match the state of the specified commit. This means all your changes will be lost unless you have them backed up elsewhere.
Consider a scenario where you’ve been working on a feature and have staged and committed changes. However, you decide that the entire feature is not needed anymore.
Check your commit history:
You see a commit hash you want to reset to, for example, i7j8k9l (the initial commit). To perform a hard reset, execute:
After this command, your working directory and staging area will match the state of the initial commit. All changes made after will be permanently lost.
Be very careful when using git reset --hard. Since it permanently deletes changes, always ensure that you have backups or that you're certain about discarding those changes.
Choosing between soft, mixed, and hard resets depends on your specific needs. Here’s a quick guide to help you decide:
Understanding how each reset mode affects the commit graph can reinforce your mental model of Git operations. Here’s a simplified view of how the different resets affect your commit history:
In this diagram:
Having explored the different reset modes, you’re now ready to dive into the concept of git revert. This command provides a safer way to undo changes by creating new commits, helping you maintain a clear commit history while addressing mistakes.
In the next chapter, we will discover how to use git revert to effectively manage unwanted changes.