Interview Prep/Git & GitHub/Lost Work, HEAD and History Problems

`fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.`

BeginnerTroubleshootingLost Work, HEAD and History Problems
Answer

Likely causes → The repo has only one commit, so there is no parent; or you are in a shallow clone, or the revision was misspelt.

Diagnose →

git rev-list --count HEAD
git rev-parse --is-shallow-repository

Fix → In a one-commit repo, use git update-ref -d HEAD to undo the first commit (keeps files staged), or git commit --amend. For shallow clones: git fetch --deepen=10.

Prevent → Use fetch-depth: 0 in CI jobs that need history.

All Git & GitHub questions Roadmap: Git & GitHub

More on Lost Work, HEAD and History Problems