Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HEAD detached at the HEAD commit id, what's the meaning?

git status says:

HEAD detached at e1997bd

and git rev-parse HEAD says:

e1997bd

What's the meaning of this?

I was thinking HEAD detached means HEAD is not pointing to to branch tip.

like image 345
KcFnMi Avatar asked Jul 16 '15 16:07

KcFnMi


People also ask

What does a detached head mean in git?

This detached head state occurs when a specific commit is checked out instead of a branch. You cannot commit to a commit—only to a branch.

How do I fix a detached head in git?

If you want to keep changes made with a detached HEAD, just create a new branch and switch to it. You can create it right after arriving at a detached HEAD or after creating one or more commits. The result is the same. The only restriction is that you should do it before returning to your normal branch.

What's a detached head?

A “detached HEAD” message in git just means that HEAD (the part of git that tracks what your current working directory should match) is pointing directly to a commit rather than a branch. Any changes that are committed in this state are only remembered as long as you don't switch to a different branch.

What is the head commit?

The term HEAD refers to the current commit you are viewing. By default, you'll view the tip of the master branch on a repository, unless the main branch of your repository has a different name. The tip of the master branch is the most recent commit on the main branch of your codebase.


1 Answers

Read through: http://gitolite.com/detached-head.html

You can also look at: http://gitolite.com/gcs.html#(48)

The head points to the commit, that's not the problem. The problem is that it's no longer a reference to a local branch name. It's the actual SHA1 hash of the commit.

This may have happened if you did:

git checkout <commit_id>
  -- or --
git checkout origin/master

To fix this, do

git checkout <branch_name>
like image 159
Mircea Avatar answered Oct 11 '22 16:10

Mircea