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

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Fred J.
  • 5,759
  • 10
  • 57
  • 106
  • 1
    Possible duplicate of [How can I reconcile detached HEAD with master/origin?](http://stackoverflow.com/questions/5772192/how-can-i-reconcile-detached-head-with-master-origin) – PeeHaa Mar 31 '16 at 17:06

3 Answers3

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
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.

Will Glück
  • 1,242
  • 12
  • 17
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.

Community
  • 1
  • 1