I made a test structure like so:
A - B - C
I checked out commit A, so I was in detached HEAD. But then I thought, "shouldn't a hard reset to the previous head do the same as checking out master?" So I tried it. I did
git reset --hard HEAD@{1}
and it said HEAD is now at 6bccb37 (commit C)
But then when I ran git status
, it said:
HEAD detached from d60bbb1 (commit A)
However, my working directory now matches commit C. Why is it still in detached HEAD state?
master
, dogit checkout master
followed bygit checkout 6bccb37
. This will take your repo to a detached HEAD state. Any time HEAD isn't pointing to a branch, the repo is in detached HEAD.