{"thread":{"id":"34259","subject":"detached HEAD before root commit - possible?","startedAt":"2013-06-23T22:55:05Z","lastAt":"2013-06-24T10:41:18Z","messageCount":5,"participants":["SZEDER Gábor","Jonathan Nieder","Martin von Zweigbergk","Junio C Hamano","Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"221746","messageId":"20130623225505.GO20052@goldbirke","threadId":"34259","inReplyTo":null,"subject":"detached HEAD before root commit - possible?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-06-23T22:55:05Z","receivedAt":"2013-06-23T22:55:05Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"I suspect that detaching HEAD before a root commit is not possible by\ndesign.  What would HEAD contain then!?  'git checkout' seems to\ncorroborate:\n\n$ git init\nInitialized empty Git repository in /tmp/test/.git/\n$ git checkout --detach\nfatal: You are on a branch yet to be born\n\nAre there some plumbing commands and options that would still allow\nthis, or can I rely on that that it's impossible?\n\n\nThanks,\nGábor\n"},{"id":"221747","messageId":"20130623235432.GA3024@elie.Belkin","threadId":"34259","inReplyTo":"20130623225505.GO20052@goldbirke","subject":"Re: detached HEAD before root commit - possible?","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-06-23T23:54:32Z","receivedAt":"2013-06-23T23:54:32Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nSZEDER Gábor wrote:\n\n> $ git init\n> Initialized empty Git repository in /tmp/test/.git/\n> $ git checkout --detach\n> fatal: You are on a branch yet to be born\n>\n> Are there some plumbing commands and options that would still allow\n> this, or can I rely on that that it's impossible?\n\ngitrepository-layout(5) tells me HEAD can be in one of a few states:\n\n a) Missing.  In this case the repository is considered to be\n    corrupt and attempts to access the repository fail until the user\n    runs \"git init\" to recover.\n\n b) A symbolic link, which is one way to represent a symref (pointing\n    to an existing branch or an unborn branch).\n\n c) A standard symref, in the format \"ref: refs/some/branch\".  Behaves\n    like (b).\n\n d) A direct SHA-1 reference (40-character commit object name)\n    pointing to a commit without associating a branch (\"detached HEAD\").\n\n e) Anything else means the repository is corrupt, as in case (a).\n\nIn other words, HEAD always either points to an unborn or existing\nbranch or an existing commit.  It's not clear to me what it would\nmean to detach from an unborn branch.\n\nImprovements to the documentation to make that clearer would of course\nbe welcome. ;-)\n\nThanks,\nJonathan\n"},{"id":"221749","messageId":"CANiSa6jNjCDjj_ZD7COXyDUx9DxFpuVqT-Lm24KQVMDK=serpw@mail.gmail.com","threadId":"34259","inReplyTo":"20130623235432.GA3024@elie.Belkin","subject":"Re: detached HEAD before root commit - possible?","fromName":"Martin von Zweigbergk","fromEmail":"martinvonz@gmail.com","sentAt":"2013-06-24T04:20:54Z","receivedAt":"2013-06-24T04:20:54Z","isPatch":false,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Sun, Jun 23, 2013 at 4:54 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n>\n> In other words, HEAD always either points to an unborn or existing\n> branch or an existing commit.  It's not clear to me what it would\n> mean to detach from an unborn branch.\n\nI think it should mean that the next commit would be a root commit (of\ncourse) and that HEAD would be detached and point to that commit. I\nfind that it helps to think of unborn branches (and \"unborn\" detached\nHEAD) as pointing to some fixed root commit.\n\nI wanted an \"unborn detached HEAD\" once when working on rebase.\nImagine what \"git rebase --root\" would do when run on a detached HEAD.\nIt is currently slightly broken because it forces the rebase (i.e.\ncreates a new root commit). This is inconsistent with e.g. \"git rebase\nHEAD~10\", which won't do anything (assuming linear history). It would\nhave been nice if \"git rebase --root\" could be implemented as:\n\n 1. create unborn detached HEAD\n 2. cherry-pick commits\n 3. set branch (or not, if started from detached HEAD)\n\nInstead, what I ended up doing at some point was to create a temporary\nunborn branch that I deleted after picking the first commit.\n\nAnyway, that was just to show another point of view; I'm not\nsuggesting we should implement support for unborn detached HEAD.\n\nMartin\n"},{"id":"221757","messageId":"7vbo6wdrvl.fsf@alter.siamese.dyndns.org","threadId":"34259","inReplyTo":"CANiSa6jNjCDjj_ZD7COXyDUx9DxFpuVqT-Lm24KQVMDK=serpw@mail.gmail.com","subject":"Re: detached HEAD before root commit - possible?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-06-24T05:01:18Z","receivedAt":"2013-06-24T05:01:18Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin von Zweigbergk <martinvonz@gmail.com> writes:\n\n> On Sun, Jun 23, 2013 at 4:54 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n>>\n>> In other words, HEAD always either points to an unborn or existing\n>> branch or an existing commit.  It's not clear to me what it would\n>> mean to detach from an unborn branch.\n>\n> I think it should mean that the next commit would be a root commit (of\n> course) and that HEAD would be detached and point to that commit.\n\nYup.  As Jonathan outlined how the current system works:\n\n - $GIT_DIR/HEAD could be a symref to a branch, which may or may not\n   exist (the latter being \"unborn\"); or\n\n - $GIT_DIR/HEAD could be directly pointing at an existing commit,\n   which is the definition of \"detached\", as you \"detach HEAD at\n   that commit\".\n\neven though such a \"I do not have any commit and I will not be on\nany branch\" state were to be supported, the consequence of that\nwould be that a natural implementation of such a state is to\nrepresent it by not having $GIT_DIR/HEAD at all.  That will break\nquite a lot of things, as such a directory $GIT_DIR will not be\ntreated as a git directory in the first place.  Of course, you could\nfix them up to support it, but I doubt if it is worth the trouble.\n"},{"id":"221781","messageId":"vpqr4frzt81.fsf@anie.imag.fr","threadId":"34259","inReplyTo":"20130623225505.GO20052@goldbirke","subject":"Re: detached HEAD before root commit - possible?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-06-24T10:41:18Z","receivedAt":"2013-06-24T10:41:18Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> I suspect that detaching HEAD before a root commit is not possible by\n> design.  What would HEAD contain then!?  'git checkout' seems to\n> corroborate:\n>\n> $ git init\n> Initialized empty Git repository in /tmp/test/.git/\n> $ git checkout --detach\n> fatal: You are on a branch yet to be born\n\nIs \"git checkout --orphan\" what you're looking for?\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}