Fred J.
Fred J.

Reputation: 6049

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

Upvotes: 1

Views: 1488

Answers (3)

Will Glück
Will Glück

Reputation: 1282

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.

Upvotes: 4

user3777273
user3777273

Reputation: 11

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.

Upvotes: 0

Mureinik
Mureinik

Reputation: 312267

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

Upvotes: 4

Related Questions