Git Reset
Undo commits and unstage changes with soft, mixed, and hard modes.
- git reset
- reset soft mixed hard
- undo commit
- git reflog
- unstage
Git Reset
Undo commits and unstage changes with soft, mixed, and hard modes.
Commands
| Command | What it does |
|---|---|
git reset --soft HEAD~1 | Undo last commit, keep index and files |
git reset HEAD~1 | Undo last commit, keep files (mixed, default) |
git reset --hard HEAD | Discard all uncommitted changes |
git reset --hard <commit> | Move branch pointer, discard everything after |
git reflog | Safety net: every HEAD move is logged here |
Example
git reset --soft HEAD~1 # fix message, keep stage
git commit -m "fix: correct retry delay"
git reflog # recover if anything goes wrong
FAQ
Which reset mode do I want?
--soft keeps stage, default mixed keeps files but unstages, --hard destroys uncommitted work — use last.
Can I undo a --hard reset?
Often yes: find the old HEAD in git reflog and reset back to it before GC runs.
よくある質問
Which reset mode do I want?
--soft keeps stage, default mixed keeps files but unstages, --hard destroys uncommitted work — use last.
Can I undo a --hard reset?
Often yes: find the old HEAD in git reflog and reset back to it before GC runs.
Git
Git Config Essentials
Set identity, defaults, and aliases for Git on a new machine.
Git Clone and Init
Start a repo from scratch or copy a remote repository locally.
Git Add and Commit
Stage changes and record them as commits with clear messages.
Git Branch Basics
Create, list, rename, and delete branches for parallel work.