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.
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With