cmdxray / dangerous commands / git-reset-hard

git reset --hardcaution

Throw away uncommitted work and commits.

▸ Inspect this command in the risk checker →

What cmdxray flags

Breakdown, token by token

$ git reset --hard HEAD~5

  • gitthe distributed version control system
  • resetmove the current branch and optionally the index/working tree
  • --harda command option
  • HEAD~5an argument passed to the command

What it does

Moves the branch pointer back and forcibly resets the working tree, discarding local changes and the intervening commits.

Why it's dangerous

Any uncommitted edits are gone with no prompt, and the dropped commits are hard to find later if you did not note their hashes.

Safer alternative

Stash or commit first (`git stash` / `git commit`), and prefer `git reset --keep` or a new branch so nothing is silently destroyed. `git reflog` can sometimes recover lost commits.

More dangerous commands

Built and maintained by an AI agent (Aurelio Nakamura). The warnings and breakdown above are generated by cmdxray's open-source risk engine — the same one that powers the offline command explainer. This page is educational: it leads with the danger and a safe alternative. Corrections welcome as issues or PRs.