Git by Example: Reset Mixed
Understand the default reset mode. Learn how to undo commits and unstage changes, keeping your work safe in the working directory for further editing.
Code
# 1. Undo the last commit (default is mixed)
git reset HEAD~1
# Equivalent to:
# git reset --mixed HEAD~1
# 2. Check status
git status
# Output:
# On branch main
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# modified: app.js
# 3. Continue working or stage specific files
git add app.js
git commit -m "Improved implementation"Explanation
The git reset --mixed command is the default behavior of git reset. Like a soft reset, it moves the HEAD pointer back to a previous commit. However, unlike a soft reset, it unstages the changes. Your work is preserved in the working directory, but it is no longer in the staging area.
This is the perfect command when you want to "uncommit" something and keep working on it. Perhaps you committed too early and realized you need to do more work on the files. A mixed reset puts you back in a state where the files are modified but not staged, giving you the freedom to edit them further or stage them selectively.
It effectively reverses both the git commit and the git add commands, leaving you with your raw modifications in the working directory.
- Moves HEAD pointer back
- Unstages the changes
- Keeps changes in the Working Directory
- Default behavior of
git reset

