Bad Revision
Error message
fatal: bad revision 'HEAD~5'
Quick summary
The revision specifier you used (e.g. HEAD~5) goes beyond the beginning of history or references a non-existent commit.
Why this happens
HEAD~N goes back more commits than exist (e.g. HEAD~5 on a repo with 3 commits)
The commit hash or branch name is misspelled
The referenced commit was garbage collected
Minimal example
git reset HEAD~5 # fatal: bad revision 'HEAD~5' (only 3 commits exist)git log --oneline # see how many commits exist
git reset HEAD~2 # use a valid numberHEAD~5 does not exist if there are fewer than 5 commits. Use git log to check, then use a valid number.
How to diagnose
Count commits with git log --oneline | wc -l to know how far back you can go
Verify the commit hash with git log --oneline | grep <partial-hash>
Check if the branch or tag exists
How to fix
Use a smaller N in HEAD~N (e.g. HEAD~1 instead of HEAD~5)
Use the correct commit hash or branch name
Check git reflog for commits that may have been orphaned
How to prevent
Verify how many commits exist before using HEAD~N
Use git log to confirm commit hashes before referencing them