Re: user manual question
- From
Björn Steinbrink <b.steinbrink@gmx.de>
- Date
- Dec 29, 2008, 17:18 UTC
- Message-ID
- <20081229171825.GB6200@atjola.homenet>
- In-Reply-To
- <gjauel$94s$4@ger.gmane.org>
On 2008.12.29 16:38:30 -0000, Zorba wrote:
Show 7 quoted lines
> so a detached HEAD is just a HEAD that is not sitting on a tip ? > > i.e. if I do $ git reset --hard HEAD^ > > ...pointing HEAD to the previous committ > > this is a detached HEAD
No. At least that won't turn an "attached" HEAD into a detached HEAD.
Attached HEAD: HEAD is a symbolic ref to another ref. Detached HEAD: HEAD is a non-symbolic ref to a commit.
So you can have: HEAD -> refs/heads/master -> commitA --> attached HEAD
Or: HEAD -> commitA --> detached HEAD
Note how the commit object is the same in both cases.
What you "git reset [--hard] HEAD^" does, depends on the kind of HEAD you have.
"git reset HEAD^" will (conceptually, implementation might differ):
Resolve HEAD^ to find a commit.
and
Resolve HEAD until it finds a non-symbolic ref, and update that ref to reference the commit it found.
Looking at the cases from above:
Attached case: HEAD -> refs/heads/master -> commitA
Resolve HEAD^: HEAD^ ==> refs/heads/master^ ==> commitA^ ==> commitA_parent
Find non-symbolic ref: HEAD (symbolic) ==> refs/heads/master (non-symbolic)
So refs/heads/master gets updated to reference commitA_parent.
Now the detached case: HEAD -> commitA
Resolve HEAD^: HEAD^ ==> commitA^ ==> commitA_parent
Find non-symbolic ref: HEAD (non-symbolic)
So HEAD gets updated to reference commitA_parent.
In other words, HEAD is what tells git what you have checked out. And that's either a branch head (attached HEAD, symbolic ref) or a commit (detached HEAD, non-symbolic ref).
In the symbolic ref case, operations like "commit" or "reset" work on the branch you have checked out (found through the symbolic ref), in the non-symbolic ref case (detached HEAD), those operations work on HEAD itself.
Björn