Git development
 help / color / mirror / Atom feed
* detached HEAD before root commit - possible?
@ 2013-06-23 22:55 SZEDER Gábor
  2013-06-23 23:54 ` Jonathan Nieder
  2013-06-24 10:41 ` Matthieu Moy
  0 siblings, 2 replies; 5+ messages in thread
From: SZEDER Gábor @ 2013-06-23 22:55 UTC (permalink / raw)
  To: git

I suspect that detaching HEAD before a root commit is not possible by
design.  What would HEAD contain then!?  'git checkout' seems to
corroborate:

$ git init
Initialized empty Git repository in /tmp/test/.git/
$ git checkout --detach
fatal: You are on a branch yet to be born

Are there some plumbing commands and options that would still allow
this, or can I rely on that that it's impossible?


Thanks,
Gábor

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: detached HEAD before root commit - possible?
  2013-06-23 22:55 detached HEAD before root commit - possible? SZEDER Gábor
@ 2013-06-23 23:54 ` Jonathan Nieder
  2013-06-24  4:20   ` Martin von Zweigbergk
  2013-06-24 10:41 ` Matthieu Moy
  1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Nieder @ 2013-06-23 23:54 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git

Hi,

SZEDER Gábor wrote:

> $ git init
> Initialized empty Git repository in /tmp/test/.git/
> $ git checkout --detach
> fatal: You are on a branch yet to be born
>
> Are there some plumbing commands and options that would still allow
> this, or can I rely on that that it's impossible?

gitrepository-layout(5) tells me HEAD can be in one of a few states:

 a) Missing.  In this case the repository is considered to be
    corrupt and attempts to access the repository fail until the user
    runs "git init" to recover.

 b) A symbolic link, which is one way to represent a symref (pointing
    to an existing branch or an unborn branch).

 c) A standard symref, in the format "ref: refs/some/branch".  Behaves
    like (b).

 d) A direct SHA-1 reference (40-character commit object name)
    pointing to a commit without associating a branch ("detached HEAD").

 e) Anything else means the repository is corrupt, as in case (a).

In other words, HEAD always either points to an unborn or existing
branch or an existing commit.  It's not clear to me what it would
mean to detach from an unborn branch.

Improvements to the documentation to make that clearer would of course
be welcome. ;-)

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: detached HEAD before root commit - possible?
  2013-06-23 23:54 ` Jonathan Nieder
@ 2013-06-24  4:20   ` Martin von Zweigbergk
  2013-06-24  5:01     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Martin von Zweigbergk @ 2013-06-24  4:20 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: SZEDER Gábor, git

On Sun, Jun 23, 2013 at 4:54 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
>
> In other words, HEAD always either points to an unborn or existing
> branch or an existing commit.  It's not clear to me what it would
> mean to detach from an unborn branch.

I think it should mean that the next commit would be a root commit (of
course) and that HEAD would be detached and point to that commit. I
find that it helps to think of unborn branches (and "unborn" detached
HEAD) as pointing to some fixed root commit.

I wanted an "unborn detached HEAD" once when working on rebase.
Imagine what "git rebase --root" would do when run on a detached HEAD.
It is currently slightly broken because it forces the rebase (i.e.
creates a new root commit). This is inconsistent with e.g. "git rebase
HEAD~10", which won't do anything (assuming linear history). It would
have been nice if "git rebase --root" could be implemented as:

 1. create unborn detached HEAD
 2. cherry-pick commits
 3. set branch (or not, if started from detached HEAD)

Instead, what I ended up doing at some point was to create a temporary
unborn branch that I deleted after picking the first commit.

Anyway, that was just to show another point of view; I'm not
suggesting we should implement support for unborn detached HEAD.

Martin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: detached HEAD before root commit - possible?
  2013-06-24  4:20   ` Martin von Zweigbergk
@ 2013-06-24  5:01     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2013-06-24  5:01 UTC (permalink / raw)
  To: Martin von Zweigbergk; +Cc: Jonathan Nieder, SZEDER Gábor, git

Martin von Zweigbergk <martinvonz@gmail.com> writes:

> On Sun, Jun 23, 2013 at 4:54 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
>>
>> In other words, HEAD always either points to an unborn or existing
>> branch or an existing commit.  It's not clear to me what it would
>> mean to detach from an unborn branch.
>
> I think it should mean that the next commit would be a root commit (of
> course) and that HEAD would be detached and point to that commit.

Yup.  As Jonathan outlined how the current system works:

 - $GIT_DIR/HEAD could be a symref to a branch, which may or may not
   exist (the latter being "unborn"); or

 - $GIT_DIR/HEAD could be directly pointing at an existing commit,
   which is the definition of "detached", as you "detach HEAD at
   that commit".

even though such a "I do not have any commit and I will not be on
any branch" state were to be supported, the consequence of that
would be that a natural implementation of such a state is to
represent it by not having $GIT_DIR/HEAD at all.  That will break
quite a lot of things, as such a directory $GIT_DIR will not be
treated as a git directory in the first place.  Of course, you could
fix them up to support it, but I doubt if it is worth the trouble.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: detached HEAD before root commit - possible?
  2013-06-23 22:55 detached HEAD before root commit - possible? SZEDER Gábor
  2013-06-23 23:54 ` Jonathan Nieder
@ 2013-06-24 10:41 ` Matthieu Moy
  1 sibling, 0 replies; 5+ messages in thread
From: Matthieu Moy @ 2013-06-24 10:41 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: git

SZEDER Gábor <szeder@ira.uka.de> writes:

> I suspect that detaching HEAD before a root commit is not possible by
> design.  What would HEAD contain then!?  'git checkout' seems to
> corroborate:
>
> $ git init
> Initialized empty Git repository in /tmp/test/.git/
> $ git checkout --detach
> fatal: You are on a branch yet to be born

Is "git checkout --orphan" what you're looking for?

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-24 10:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-23 22:55 detached HEAD before root commit - possible? SZEDER Gábor
2013-06-23 23:54 ` Jonathan Nieder
2013-06-24  4:20   ` Martin von Zweigbergk
2013-06-24  5:01     ` Junio C Hamano
2013-06-24 10:41 ` Matthieu Moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox