{"thread":{"id":"28636","subject":"Recovering Committed Changes in a Detached Head?","startedAt":"2011-10-08T20:58:07Z","lastAt":"2011-10-10T01:26:06Z","messageCount":10,"participants":["Daly Gutierrez","SZEDER Gábor","Martin Fick","Joel C. Salomon","Nguyen Thai Ngoc Duy","Ronan Keryell","Matthieu Moy","Junio C Hamano","Miles Bader"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"177249","messageId":"1318107488.5865.46.camel@R0b0ty","threadId":"28636","inReplyTo":null,"subject":"Recovering Committed Changes in a Detached Head?","fromName":"Daly Gutierrez","fromEmail":"daly.gutierrez@gmail.com","sentAt":"2011-10-08T20:58:07Z","receivedAt":"2011-10-08T20:58:07Z","isPatch":false,"sender":{"key":"daly.gutierrez@gmail.com","avatar":null},"body":"Is this possible after changing from the Detached Head branch to an\nexisting branch?  How about if I don't remember the commit SHA1 ID?\n\nWhat I did, to the best of my knowledge:\n1) Checked out a previous version:\n> git checkout 3a5bb38a83c00f7acab573f0ec836577143200aa\n\n2) Modified file and committed the changes in the detached branch.\n> git log\n commit 92aa5381b9f7229523dba42aa94735c30f173451\n Author: Daly Gutierrez <Daly.Gutierrez@gmail.com>\n Date:   Sat Oct 8 16:20:11 2011 -0400\n\n    Committing this in the Detached Head\n\n3) For curiosity,\n> git branch\n* (no branch)\n  New_Branch\n  Second_New_Branch\n  master\n\n4) Changed to 'New_Branch' branch...  I no longer see the detached\nbranch...\n > git branch\n* New_Branch\n  Second_New_Branch\n  master\n\n5) Want to access the file with the changes I made in the Detached\nbranch, but don't know how...  PLEASE HELP?\n"},{"id":"177251","messageId":"20111008213741.GA24409@goldbirke","threadId":"28636","inReplyTo":"1318107488.5865.46.camel@R0b0ty","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-10-08T21:37:41Z","receivedAt":"2011-10-08T21:37:41Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nOn Sat, Oct 08, 2011 at 04:58:07PM -0400, Daly Gutierrez wrote:\n> Is this possible after changing from the Detached Head branch to an\n> existing branch?  How about if I don't remember the commit SHA1 ID?\n> \n> What I did, to the best of my knowledge:\n> 1) Checked out a previous version:\n> > git checkout 3a5bb38a83c00f7acab573f0ec836577143200aa\n> \n> 2) Modified file and committed the changes in the detached branch.\n> > git log\n>  commit 92aa5381b9f7229523dba42aa94735c30f173451\n>  Author: Daly Gutierrez <Daly.Gutierrez@gmail.com>\n>  Date:   Sat Oct 8 16:20:11 2011 -0400\n> \n>     Committing this in the Detached Head\n> \n> 3) For curiosity,\n> > git branch\n> * (no branch)\n>   New_Branch\n>   Second_New_Branch\n>   master\n> \n> 4) Changed to 'New_Branch' branch...  I no longer see the detached\n> branch...\n>  > git branch\n> * New_Branch\n>   Second_New_Branch\n>   master\n> \n> 5) Want to access the file with the changes I made in the Detached\n> branch, but don't know how...  PLEASE HELP?\n\ngit reflog to the rescue.  For your example above it will output\nsomething like this:\n\n  deadbeef HEAD@{0}: checkout: moving from 92aa5381b9f7229523dba42aa94735c30f173451 to New_Branch\n  92aa5381 HEAD@{1}: commit: Committing this in the Detached Head\n  3a5bb38a HEAD@{2}: checkout: moving from master to 3a5bb38a83c00f7acab573f0ec836577143200aa\n  deafbabe HEAD@{3}: ...\n  ...\n\nThere you see the first line of the commit message from your \"lost\"\ncommit, and you can do\n\n  git checkout -b lost_detached_head 92aa5381\n\nand you get a branch pointing to that commit you made while on\ndetached head, and you can work with it as usual.\n\n\nBest,\nGábor\n"},{"id":"177252","messageId":"ab706826-75df-4410-941e-6b40ec92713c@email.android.com","threadId":"28636","inReplyTo":"20111008213741.GA24409@goldbirke","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Martin Fick","fromEmail":"mfick@codeaurora.org","sentAt":"2011-10-08T22:00:33Z","receivedAt":"2011-10-08T22:00:33Z","isPatch":false,"sender":{"key":"mfick@codeaurora.org","avatar":null},"body":">git reflog to the rescue.  For your example above it will output\n>something like this:\n>\n>deadbeef HEAD@{0}: checkout: moving from\n>92aa5381b9f7229523dba42aa94735c30f173451 to New_Branch\n>  92aa5381 HEAD@{1}: commit: Committing this in the Detached Head\n>3a5bb38a HEAD@{2}: checkout: moving from master to\n>3a5bb38a83c00f7acab573f0ec836577143200aa\n>  deafbabe HEAD@{3}: ...\n>  ...\n>\n>There you see the first line of the commit message from your \"lost\"\n>commit, and you can do\n>\n>  git checkout -b lost_detached_head 92aa5381\n>\n>and you get a branch pointing to that commit you made while on\n>detached head, and you can work with it as usual.\n\nWhile rflog is cool, I can't help but think that git could be even more helpful for these scenarios.\n\nFirst, maybe git could create refs for these automatically, perhaps with a name like orphans/1?  Maybe these refs would only be visible via git branch --orphans.\n\n-Martin\nEmployee of Qualcomm Innovation Center,Inc. which is a member of Code Aurora Forum\n"},{"id":"177258","messageId":"4E9115B0.3030701@gmail.com","threadId":"28636","inReplyTo":"ab706826-75df-4410-941e-6b40ec92713c@email.android.com","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Joel C. Salomon","fromEmail":"joelcsalomon@gmail.com","sentAt":"2011-10-09T03:32:00Z","receivedAt":"2011-10-09T03:32:00Z","isPatch":false,"sender":{"key":"joelcsalomon@gmail.com","avatar":"https://gravatar.com/avatar/271ed240fc850235728b19d5b2b9f38c41ebdf0209c5b663f8b07060950489e6?d=mp&s=160"},"body":"On 10/08/2011 06:00 PM, Martin Fick wrote:\n>> git reflog to the rescue.\n<snip>\n>> There you see the first line of the commit message from your \"lost\"\n>> commit, and you can do\n>>\n>>  git checkout -b lost_detached_head 92aa5381\n>>\n>> and you get a branch pointing to that commit you made while on\n>> detached head, and you can work with it as usual.\n> \n> While rflog is cool, I can't help but think that git could be even more helpful for these scenarios.\n> \n> First, maybe git could create refs for these automatically, perhaps with a name like orphans/1?  Maybe these refs would only be visible via git branch --orphans.\n\nCreating these \"orphan\" refs would require the equivalent of (part of)\ngit-fsck; I can't imagine that could be imposed without significant\noverhead on too many operations.  I think you'd be better off wrapping\ngit-fsck in a script that can create these branches.\n\n--Joel\n"},{"id":"177259","messageId":"160538a7-a5cf-48d6-b89e-f53f79ed25b6@email.android.com","threadId":"28636","inReplyTo":"4E9115B0.3030701@gmail.com","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Martin Fick","fromEmail":"mfick@codeaurora.org","sentAt":"2011-10-09T05:39:04Z","receivedAt":"2011-10-09T05:39:04Z","isPatch":false,"sender":{"key":"mfick@codeaurora.org","avatar":null},"body":"\n\n\"Joel C. Salomon\" <joelcsalomon@gmail.com> wrote:\n\n>On 10/08/2011 06:00 PM, Martin Fick wrote:\n>>> git reflog to the rescue.\n><snip>\n>>> There you see the first line of the commit message from your \"lost\"\n>>> commit, and you can do\n>>>\n>>>  git checkout -b lost_detached_head 92aa5381\n>>>\n>>> and you get a branch pointing to that commit you made while on\n>>> detached head, and you can work with it as usual.\n>> \n>> While rflog is cool, I can't help but think that git could be even\n>more helpful for these scenarios.\n>> \n>> First, maybe git could create refs for these automatically, perhaps\n>with a name like orphans/1?  Maybe these refs would only be visible via\n>git branch --orphans.\n>\n>Creating these \"orphan\" refs would require the equivalent of (part of)\n>git-fsck; I can't imagine that could be imposed without significant\n>overhead on too many operations.  I think you'd be better off wrapping\n>git-fsck in a script that can create these branches.\n \nIs there another way to create orphan refs than by doing a checkout and leaving the orphan behind?  I guess a rebase or other branch rewinding operations, but shouldn't it already know on those that that if it alters anything, it will create an orphan?  Git already checks for to see if it is leaving orphan refs behind on a checkout, why not just give the orphan a branch name at those points (not sure what to do if the check is bypassed with -q, just punt I guess)? \n\n-Martin \n\n\nEmployee of Qualcomm Innovation Center,Inc. which is a member of Code Aurora Forum\n"},{"id":"177261","messageId":"CACsJy8CsMCju7joj2B2xbBSTF1vHjyuFeSZyPhTJisO2sU-Fqg@mail.gmail.com","threadId":"28636","inReplyTo":"ab706826-75df-4410-941e-6b40ec92713c@email.android.com","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-10-09T05:52:11Z","receivedAt":"2011-10-09T05:52:11Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Oct 9, 2011 at 9:00 AM, Martin Fick <mfick@codeaurora.org> wrote:\n>>git reflog to the rescue.  For your example above it will output\n>>something like this:\n>>\n>>deadbeef HEAD@{0}: checkout: moving from\n>>92aa5381b9f7229523dba42aa94735c30f173451 to New_Branch\n>>  92aa5381 HEAD@{1}: commit: Committing this in the Detached Head\n>>3a5bb38a HEAD@{2}: checkout: moving from master to\n>>3a5bb38a83c00f7acab573f0ec836577143200aa\n>>  deafbabe HEAD@{3}: ...\n>>  ...\n>>\n>>There you see the first line of the commit message from your \"lost\"\n>>commit, and you can do\n>>\n>>  git checkout -b lost_detached_head 92aa5381\n>>\n>>and you get a branch pointing to that commit you made while on\n>>detached head, and you can work with it as usual.\n>\n> While rflog is cool, I can't help but think that git could be even more helpful for these scenarios.\n>\n> First, maybe git could create refs for these automatically, perhaps with a name like orphans/1?  Maybe these refs would only be visible via git branch --orphans.\n\nIf I remember correctly, we don't have private ref namespace, any refs\ncreated automatically this way could be pushed out by accident.\n-- \nDuy\n"},{"id":"177262","messageId":"87k48efvzc.fsf@an-dro.info.enstb.org","threadId":"28636","inReplyTo":"CACsJy8CsMCju7joj2B2xbBSTF1vHjyuFeSZyPhTJisO2sU-Fqg@mail.gmail.com","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Ronan Keryell","fromEmail":"ronan.keryell@hpc-project.com","sentAt":"2011-10-09T07:46:31Z","receivedAt":"2011-10-09T07:46:31Z","isPatch":false,"sender":{"key":"ronan.keryell@hpc-project.com","avatar":null},"body":">>>>> On Sun, 9 Oct 2011 16:52:11 +1100, Nguyen Thai Ngoc Duy <pclouds@gmail.com> said:\n\n    Nguyen> On Sun, Oct 9, 2011 at 9:00 AM, Martin Fick <mfick@codeaurora.org> wrote:\n\n    >> While rflog is cool, I can't help but think that git could be\n    >> even more helpful for these scenarios.\n\n    >> First, maybe git could create refs for these automatically,\n    >> perhaps with a name like orphans/1?  Maybe these refs would only\n    >> be visible via git branch --orphans.\n\n    Nguyen> If I remember correctly, we don't have private ref\n    Nguyen> namespace, any refs created automatically this way could be\n    Nguyen> pushed out by accident.\n\nA way to avoid this could be to deal with this like git-stash works,\ninstead of relying on the branch machinery.\n\nBut anyway, I think there is a trade-off between keeping some references\nto some hypothetical future use and preventing the garbage collector to\nreclaim useless objects...\n-- \n  Ronan KERYELL                      |\\/  Phone:  +1 408 844 HPC0\n  HPC Project, Inc.                  |/)  Cell:   +33 613 143 766\n  5201 Great America Parkway #3241   K    Ronan.Keryell@hpc-project.com\n  Santa Clara, CA 95054              |\\   skype:keryell\n  USA                                | \\  http://hpc-project.com\n"},{"id":"177263","messageId":"vpqvcry4m8p.fsf@bauges.imag.fr","threadId":"28636","inReplyTo":"ab706826-75df-4410-941e-6b40ec92713c@email.android.com","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2011-10-09T08:12:22Z","receivedAt":"2011-10-09T08:12:22Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Martin Fick <mfick@codeaurora.org> writes:\n\n>>git reflog to the rescue.  For your example above it will output\n>>something like this:\n>>\n>>deadbeef HEAD@{0}: checkout: moving from\n>>92aa5381b9f7229523dba42aa94735c30f173451 to New_Branch\n>>  92aa5381 HEAD@{1}: commit: Committing this in the Detached Head\n>>3a5bb38a HEAD@{2}: checkout: moving from master to\n>>3a5bb38a83c00f7acab573f0ec836577143200aa\n>>  deafbabe HEAD@{3}: ...\n>>  ...\n>>\n>>There you see the first line of the commit message from your \"lost\"\n>>commit, and you can do\n>>\n>>  git checkout -b lost_detached_head 92aa5381\n>>\n>>and you get a branch pointing to that commit you made while on\n>>detached head, and you can work with it as usual.\n>\n> While rflog is cool, I can't help but think that git could be even more helpful for these scenarios.\n\nGit has been showing a big scary warning when entering detached HEAD,\nand now has another helpful one when leaving a commit orphan:\n\n$ git checkout HEAD^\nNote: checking out 'HEAD^'.\n\nYou are in 'detached HEAD' state. You can look around, make experimental\nchanges and commit them, and you can discard any commits you make in this\nstate without impacting any branches by performing another checkout.\n\nIf you want to create a new branch to retain commits you create, you may\ndo so (now or later) by using -b with the checkout command again. Example:\n\n  git checkout -b new_branch_name\n\nHEAD is now at adcbd2f... foo\n\n$ date > foo.txt; git add foo.txt; git commit -am \"commited on detached HEAD\"\n[detached HEAD 9e9c4ef] commited on detached HEAD\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\n$ git checkout master\nWarning: you are leaving 1 commit behind, not connected to\nany of your branches:\n\n  9e9c4ef commited on detached HEAD\n\nIf you want to keep them by creating a new branch, this may be a good time\nto do so with:\n\n git branch new_branch_name 9e9c4efeca049ca559541595c9ca4a3380dee523\n\nSwitched to branch 'master'\n\n(since 8e2dc6ac06ae90, Junio C Hamano, Fri Feb 18 16:04:47 2011, commit:\ngive final warning when reattaching HEAD to leave commits behind)\n\nI think these warnings are (scary and big) enough.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"177290","messageId":"7vfwj1px6h.fsf@alter.siamese.dyndns.org","threadId":"28636","inReplyTo":"ab706826-75df-4410-941e-6b40ec92713c@email.android.com","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-10-09T23:22:46Z","receivedAt":"2011-10-09T23:22:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Martin Fick <mfick@codeaurora.org> writes:\n\n> While rflog is cool,...\n>\n> First, maybe git could create refs for these automatically, perhaps with a name like orphans/1?  Maybe these refs would only be visible via git branch --orphans.\n\nInstead of spelling them orphans/$n, you already have @{$n}.\n"},{"id":"177292","messageId":"87sjn1fxht.fsf@catnip.gol.com","threadId":"28636","inReplyTo":"7vfwj1px6h.fsf@alter.siamese.dyndns.org","subject":"Re: Recovering Committed Changes in a Detached Head?","fromName":"Miles Bader","fromEmail":"miles@gnu.org","sentAt":"2011-10-10T01:26:06Z","receivedAt":"2011-10-10T01:26:06Z","isPatch":false,"sender":{"key":"miles@gnu.org","avatar":"https://gravatar.com/avatar/01069b69593af7bff28e2f97afeb3644ae6fe2f5f56cb3a8cf34c5fb8c36efe5?d=mp&s=160"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n>> First, maybe git could create refs for these automatically, perhaps\n>> with a name like orphans/1?  Maybe these refs would only be visible\n>> via git branch --orphans.\n>\n> Instead of spelling them orphans/$n, you already have @{$n}.\n\nHmm, shouldn't that be \"HEAD@{$n}\" (as the reflog output suggests)?\n\n[Well, I dunno, I'm generally kind of confused by the @{...} notation,\nbut I just tried it out, and just @{$n} seems to refer to the current\nbranch, which presumably won't include the orphaned bit once one it's\nbeen orphaned...]\n\nThanks,\n\n-Miles\n\n-- \n`The suburb is an obsolete and contradictory form of human settlement'\n"}]}