git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Recovering Committed Changes in a Detached Head?

From
MFMartin Fick <mfick@codeaurora.org>
Date
Oct 9, 2011, 05:39 UTC
Message-ID
<160538a7-a5cf-48d6-b89e-f53f79ed25b6@email.android.com>
In-Reply-To
<4E9115B0.3030701@gmail.com>
"Joel C. Salomon" <joelcsalomon@gmail.com> wrote:
Show 22 quoted lines
>On 10/08/2011 06:00 PM, Martin Fick wrote:
>>> git reflog to the rescue.
><snip>
>>> There you see the first line of the commit message from your "lost"
>>> commit, and you can do
>>>
>>>  git checkout -b lost_detached_head 92aa5381
>>>
>>> and you get a branch pointing to that commit you made while on
>>> detached head, and you can work with it as usual.
>> 
>> While rflog is cool, I can't help but think that git could be even
>more helpful for these scenarios.
>> 
>> 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.
>
>Creating these "orphan" refs would require the equivalent of (part of)
>git-fsck; I can't imagine that could be imposed without significant
>overhead on too many operations.  I think you'd be better off wrapping
>git-fsck in a script that can create these branches.
 
Is 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)? 
-Martin 
Employee of Qualcomm Innovation Center,Inc. which is a member of Code Aurora Forum
Previous: Joel C. SalomonNext: Nguyen Thai Ngoc Duy
Message 5 of 10 in “Recovering Committed Changes in a Detached Head?”
  1. Daly GutierrezOct 8, 2011
  2. SZEDER GáborOct 8, 2011
  3. Martin FickOct 8, 2011
  4. Joel C. SalomonOct 9, 2011
  5. Martin FickOct 9, 2011
  6. Nguyen Thai Ngoc DuyOct 9, 2011
  7. Ronan KeryellOct 9, 2011
  8. Matthieu MoyOct 9, 2011
  9. Junio C HamanoOct 9, 2011
  10. Miles BaderOct 10, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.