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

CommandWhat it does
git reset --soft HEAD~1Undo last commit, keep index and files
git reset HEAD~1Undo last commit, keep files (mixed, default)
git reset --hard HEADDiscard all uncommitted changes
git reset --hard <commit>Move branch pointer, discard everything after
git reflogSafety 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.

Soalan Lazim

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