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

`fatal: Cannot do hard reset with paths.`

BeginnerTroubleshootingLost Work, HEAD and History Problems
Answer

Likely causes → You tried git reset --hard <file>. Hard reset works on the whole tree, not on single paths.

Diagnose → Re-read your command: path arguments are only allowed with mixed or soft modes.

Fix → To restore one file to HEAD: git restore --source=HEAD --staged --worktree path/to/file. To restore from another commit: git restore --source=<sha> path. To unstage only: git reset path or git restore --staged path.

Prevent → Use git restore for files and git reset for branches.

All Git & GitHub questions Roadmap: Git & GitHub

More on Lost Work, HEAD and History Problems