git reset –mixed
Syntax
git reset --mixed <commit>
Uses of git reset –mixed
- Default Mode: If no option is provided, git reset defaults to –mixed.
- Updates Staging Area: Changes the staging area to match the specified commit, effectively un-staging files that were previously staged.
- Preserves Working Directory: Leaves the working directory unchanged, so any modifications remain in your files.
Example
Consider you have a commit history like this:
A -- B -- C (HEAD)
Running the following command:
git reset --mixed B
The result is:
- HEAD points to commit B.
- Staging area matches commit B.
- Working directory contains changes from commit C as un-staged modifications.
Use Case
Use –mixed when you want to keep your working changes but remove them from the staging area. This is useful if you realize the changes should not be staged yet but you still want to continue working on them.
What’s The Difference Between git reset –mixed, –soft, and –hard?
Git is an important tool for version control in software development. Among its numerous commands, git reset is one of the most powerful but also one of the most complex, especially with its different options: –mixed, –soft, and –hard. This article explains these options, their syntax, features, and uses, and provides practical examples to help you understand their differences and use cases.