1

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?

rb612
  • 5,280
  • 3
  • 30
  • 68
  • What your example illustrates is that a branch isn't the same as the commit it is currently pointing to. To see this in an even less convoluted way, assuming you have a branch called `master`, do `git checkout master` followed by `git 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. – Pradhan Nov 14 '15 at 06:17
  • @Pradhan ah that's exactly what I was looking for!! Thank you! – rb612 Nov 14 '15 at 06:26

0 Answers0