Say I\'m in a Git repository. I delete a file and commit that change. I continue working and make some more commits. Then, I find I need to restore that file.
I know
I had the same question. Without knowing it, I had created a dangling commit.
List dangling commits
git fsck --lost-found
Inspect each dangling commit
git reset --hard
My files reappeared when I moved to the dangling commit.
git status for the reason:
git status
“HEAD detached from ”