1

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

1

3 Answers 3

4

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.

4

Nothing is really broken, you're just on a detached HEAD. Simply give it a name, like any other branch, and continue working on it:

$ git checkout -b my_new_branch
3
  • how to go back to master? Commented Jun 10, 2020 at 21:33
  • @javadba you can use checkout: git checkout master.
    – Mureinik
    Commented Jun 11, 2020 at 6:04
  • figured that out. I had a couple of times over the years that I did not know what to do here: but now all is clear . Commented Jun 11, 2020 at 6:27
0

You can find an answer here: GIT restore last detached HEAD

Also, the Pluralsight video "How Git Works" explains how this happens and what to do about it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.