agentsclimarketplace

Git reset mechanics

Skill narenaryan/agent-skills/skills/git/git-reset-mechanics

Byte-sized agent skills for giving advanced knowledge to AI agents

Install
npx -y skills add narenaryan/agent-skills --skill git-reset-mechanics

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when undoing commits, unstaging files, or choosing between reset/checkout/restore — clarifies which tree each variant touches and when --hard is unsafe

SKILL.md

1.7 KB, as published. Nobody here has run it

Git Reset Mechanics

Three trees: HEAD (last commit), Index (staged), Working (disk). reset walks them in order and stops by flag.

FlagHEAD refIndexWorkdirWD-safe
--softmovesyes
--mixed (default)movesresetsyes
--hardmovesresetsresetsNO

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> — unstage
  • git restore <path> — discard workdir change
  • git 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

  • --hard is the only destructive common flag — no prompt. Recovery: git refloggit reset --hard HEAD@{1}.
  • Reset on a pushed branch rewrites history others have. Use revert instead.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.