git-reset-mechanics
Installation
SKILL.md
Git Reset Mechanics
Three trees: HEAD (last commit), Index (staged), Working (disk). reset walks them in order and stops by flag.
| Flag | HEAD ref | Index | Workdir | WD-safe |
|---|---|---|---|---|
--soft |
moves | — | — | yes |
--mixed (default) |
moves | resets | — | yes |
--hard |
moves | resets | resets | NO |
Reset vs Checkout (no path)
git reset --hard <ref>moves the branch HEAD points to; overwrites workdir without checking.git checkout <ref>moves HEAD (detaches if a commit); refuses if unsaved changes conflict.
With a Path
git reset <commit> -- <path> copies commit→index, skips HEAD move (can't partially move a pointer). --hard with a path is rejected.
git checkout <commit> -- <path> copies commit→index and workdir — destructive. Prefer modern restore:
git restore --staged <path>— unstagegit restore <path>— discard workdir changegit restore --source=<ref> -SW <path>— both
Patterns
git reset --soft HEAD~ # undo commit, keep staging
git reset HEAD~ # undo commit + unstage
git reset --hard HEAD~ # undo + discard (destructive)
git reset --soft HEAD~3 && git commit # squash last 3
git reset --patch # unstage hunks
Pitfalls
--hardis the only destructive common flag — no prompt. Recovery:git reflog→git reset --hard HEAD@{1}.- Reset on a pushed branch rewrites history others have. Use
revertinstead.
Weekly Installs
3
Repository
narenaryan/agent-skillsFirst Seen
1 day ago
Security Audits
Installed on
amp3
cline3
opencode3
cursor3
kimi-cli3
warp3