Resetting states, restoring working directories, and reverting history.
Case 1: Staged changes (Unstaging files)
If you ran git add but decided you aren't ready to commit those files yet, unstage them using:
# Unstage a specific file
git reset index.html
# Unstage all staged changes
git resetCase 2: Committed changes (Undoing commits)
If you committed changes locally but want to pull that commit back, you can reset. Git defines three modes of resetting, referencing HEAD~1 (one commit back from active branch point):
| Reset Mode | Impact on Working Directory | Impact on Staging Area | Log History |
|---|---|---|---|
Soft (--soft) | Keeps all modified files intact | Keeps all staged changes intact | Moves commit pointer back |
| Mixed (Default) | Keeps all modified files intact | Unstages all changes | Moves commit pointer back |
Hard (--hard) | Deletes all working changes | Deletes all staged changes | Moves commit pointer back |
Running a Hard Reset
# WARNING: This destroys all uncommitted local modifications permanently
git reset --hard HEAD~1
# Reset to a specific commit hash in history
git reset --hard a1b2c3d