A Real, Disposable Commit
git checkout -b reset-practice
# create experiment.md
git commit -m "Try a new experimental garnish idea"
A dedicated throwaway branch — nothing here touches master.
--soft: Uncommit, Keep It Staged
git reset --soft HEAD~1
git status
The commit is genuinely gone from the log, but experiment.md is right back in the staging area — ready to be recommitted immediately, perhaps with a different message.
--mixed (the default): Uncommit and Unstage
git commit -m "Try a new experimental garnish idea" # recreate it
git reset HEAD~1
git status
Same uncommit, but the staging area is also cleared — experiment.md is back to untracked, its content still genuinely sitting on disk.
--hard: Uncommit, Unstage, and Discard
git add experiment.md && git commit -m "Try a new experimental garnish idea" # recreate it again
git reset --hard HEAD~1
ls
The commit is gone, and so is the file itself — genuinely removed from the working directory. This is the one mode where real content is actually lost, not just re-staged.
A real experimental garnish idea gets committed on its own throwaway branch — reset-practice, branched off master specifically so nothing here risks the real project. "Undo this commit" sounds like one request, but git genuinely offers three different answers, depending on what should happen to the file itself.
This lesson recreates the exact same commit three times and undoes it a different way each time, so the real difference between soft, mixed, and hard is something you see directly rather than memorize from a table.
git reset --soft HEAD~1
Moves the branch pointer back one commit; the staging area and working directory are both left exactly as they were. Confirmed directly in this lab: the undone commit's changes landed right back in the staging area, ready to recommit.
git reset HEAD~1 (mixed, the default)
Moves the branch pointer back one commit AND clears the staging area; the working directory is untouched. Confirmed directly in this lab: experiment.md genuinely reverted to untracked, its content still present on disk.
git reset --hard HEAD~1
Moves the branch pointer back one commit, clears the staging area, AND overwrites the working directory to match the target commit — discarding anything the undone commit added. Confirmed directly in this lab: experiment.md was genuinely gone from disk afterward.
Takeaways
- All three reset modes move the branch pointer back to an earlier commit — that part is always the same
- git reset --soft leaves the staging area and working directory completely untouched — maximum flexibility
- git reset (mixed, the default) also clears the staging area, but keeps the actual file content on disk
- git reset --hard also overwrites the working directory — the only mode where real content is genuinely discarded
- Reset is for local, private branches — a shared or pushed commit calls for git revert instead, covered in Certificate 2