git reset –soft
Syntax
git reset --soft <commit>
Uses of git reset –soft
- Updates HEAD Only: Moves HEAD to the specified commit without affecting the staging area or working directory.
- Preserves Staging Area: Keeps changes in the staging area.
- Preserves Working Directory: Leaves the working directory unchanged.
Example
Given a commit history like this:
A -- B -- C (HEAD)
Running the command:
git reset --soft B
The result is:
- HEAD points to commit B.
- Staging area retains changes from commit C.
- Working directory contains changes from commit C.
Use Case
Use –soft when you want to adjust the commit history (e.g., remove the latest commit) but keep all the changes in both the staging area and the working directory, allowing you to commit them again.
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.