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

Re: [PATCH] logging branch deletion to help recovering from mistakes

From
Jeff King <peff@peff.net>
Date
Dec 7, 2010, 18:12 UTC
Message-ID
<20101207181201.GB26137@sigill.intra.peff.net>
In-Reply-To
<20101207175418.GU355@fearengine.rdu.redhat.com>
On Tue, Dec 07, 2010 at 12:54:18PM -0500, Casey Dahlin wrote:
Show 15 quoted lines
> On Tue, Dec 07, 2010 at 11:45:20AM -0600, Jonathan Nieder wrote:
> > Casey Dahlin wrote:
> > 
> > > Could commits made onto a detached head also show up here? Or is that
> > > better thwarted with another mechanism?
> > 
> > I think that's better thwarted with the HEAD reflog:
> > 
> > 	$ git log -g HEAD
> 
> I was more worried about changes that were made onto a detached head,
> and then the head was reattached, leaving the new commits dangling.
> 
> The end result is identical to a deleted branch, just wondering if we
> should note it in the same place.

We have enough information in the HEAD reflog already to reconstruct those sorts of things.

You can detect entering and leaving the detached HEAD in the reflog. The reflog comments look something like this:

  checkout: moving from $SOME_BRANCH to $SOME_SHA1
  commit: $SOME_COMMIT_MESSAGE
  checkout: moving from $SOME_OTHER_SHA1 to $BRANCH|$SHA1

So from that you can see that we entered a detached HEAD state, made a commit, and that commit became dangling when we moved. One could write a script to search for these cases (but note that most detached instances just involve rebasing, which is probably not interesting, as we install the result into the branch tip at the end).

I don't think this belongs in the same realm as "deleted branches", but I do think we could have a special option to "git fsck" to stick these into lost-found.

-Peff
Previous: Jonathan Nieder
Message 28 of 28 in “logging branch deletion to help recovering from mistakes”
  1. logging branch deletion to help recovering from mistakesJunio C Hamano, Dec 6, 2010
  2. Štěpán NěmecDec 6, 2010
  3. Andreas SchwabDec 6, 2010
  4. Nguyen Thai Ngoc DuyDec 7, 2010
  5. Junio C HamanoDec 7, 2010
  6. Nguyen Thai Ngoc DuyDec 7, 2010
  7. Michael J GruberDec 7, 2010
  8. Nguyen Thai Ngoc DuyDec 7, 2010
  9. Jakub NarebskiDec 7, 2010
  10. Nguyen Thai Ngoc DuyDec 7, 2010
  11. Jeff KingDec 7, 2010
  12. Shawn PearceDec 7, 2010
  13. Jeff KingDec 7, 2010
  14. Shawn O. PearceDec 7, 2010
  15. Jeff KingDec 7, 2010
  16. Shawn O. PearceDec 7, 2010
  17. Jeff KingDec 7, 2010
  18. Shawn O. PearceDec 7, 2010
  19. Junio C HamanoDec 7, 2010
  20. Jeff KingDec 7, 2010
  21. Casey DahlinDec 7, 2010
  22. Jonathan NiederDec 7, 2010
  23. Casey DahlinDec 7, 2010
  24. Jonathan NiederDec 7, 2010
  25. Casey DahlinDec 7, 2010
  26. Junio C HamanoDec 7, 2010
  27. Jonathan NiederDec 7, 2010
  28. Jeff KingDec 7, 2010

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.