Search code examples
gitgit-detached-head

git HEAD detached from after reset --hard


I needed to do away with changes that I made to the working directory and go back and start from the last commit, so I did git reset --hard

Now when I do git commit and git status I get this string in red saying "HEAD detached from: and some 7 char number. I did few commits since then but not sure about this red message.

Did I muck it up and what am I suppose to do to "fix" it? or it is not broken? Thanks


Solution

  • Create a branch, then merge it/rebase it to the original branch (let's suppose master). It should solve the problem.

    $ git checkout -b temp_branch
    $ git rebase master
    $ git checkout master
    $ git merge temp_branch
    

    Apparently you didn't just reset the workspace but moved the HEAD to another commit.