Thread (4 messages) flat view 4 messages, 4 authors, 2016-06-15

Re: master^ is not a local branch -- huh?!?

From: Nicolas Pitre <nico@fluxnic.net>
Date: 2016-06-15 22:48:09

On Mon, 1 Feb 2010, Ron Garret wrote:
In article [ref], Sergei Organov [off-list ref] 
wrote:
quoted
Junio C Hamano [off-list ref] writes:
quoted
Steve Diver [off-list ref] writes:
[...]
quoted
If read carefully (some may argue that it does not need a very careful
reading to get it, though), this hints that "detached HEAD" state is a
substitute for using a temporary branch, but it may not be strong
enough.
For my rather fresh eye it looks more like unnamed (anonymous?) branch
than a temporary one. Doesn't detached HEAD behave exactly like a
regular HEAD but pointing to the tip of an unnamed branch?
I strongly concur with this.

And as long as I'm weighing in, it would also help to prevent confusion 
if it were made clear that this unnamed branch doesn't actually come 
into existence unless and until you do a commit.
Nope.  Creating a commit doesn't create any branch.  A commit creation 
merely adds a new node in the history graph, and links it to the commit 
that was the current one before that commit operation.  If HEAD is 
_attached_ to a branch then the branch pointer is also updated to point 
to that new commit.  If HEAD is _detached_ then no branch is updated and 
HEAD simply carries a direct reference to that new commit.

At a later time you can:

1) Create a new branch pointer which default value is the commit pointed to
   by HEAD.  This is true whether or not HEAD is detached, but in this 
   case this is an interesting property.

2) Move HEAD somewhere else by performing a checkout.  If HEAD was 
   detached then its last position is simply forgotten and those 
   commits that were performed while HEAD was detached, if any, are 
   simply left dangling and eventually garbage collected.  If however a 
   new branch pointer was created in (1) then those commits won't be 
   dangling.

In any case, a detached HEAD is not only a temporary branch, it is also 
a volatile branch.  And in the Git model, it is simply not a branch at 
all.  Hence the 2 states for HEAD: either detached, or attached to a 
branch pointer.


Nicolas
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help