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, 19:38 UTC
Message-ID
<20101207193804.GA27685@sigill.intra.peff.net>
In-Reply-To
<7v7hflqth1.fsf@alter.siamese.dyndns.org>
On Tue, Dec 07, 2010 at 11:21:46AM -0800, Junio C Hamano wrote:
Show 7 quoted lines
> I am more worried about stuff in branch.<name>.* that are discarded upon
> "branch -d".  Without the config items, you won't have a working:
> 
>     $ branch -d frotz
>     $ branch --undelete frotz
>     $ git checkout frotz
>     $ git pull
Hmm, yeah, I didn't think about that. Two possible solutions:
  1. Just leave it in .git/config. It is not hurting anything if the
     branch does not exist, but it is cruft in a file the user might
     look at.
  2. Drop it into .git/config.dead/<branch_name>. When resurrecting a
     branch, copy it back into .git/config.

In both cases, when the reflog for the deleted branch is pruned to nothing, we delete the relevant config, too.

In the second case, I think you would have to take special care for something like:

  $ git branch frotz origin/master
  $ git branch -d frotz
  $ git remote rename origin foo
  $ git branch --undelete frotz

In the non-deleted case, this transparently renames branch.frotz.remote from "origin" to "foo". In the deleted case, we would need to make sure the dead config is updated, too.

To be honest, I have never been that interested in a "branch --undelete" feature. I much more care about leaving the reflogs of deleted branches around, so I can "git checkout -b foo bar@{1}" later on[1]. That is, to me branch undeletion is not about bringing a branch back wholesale, but rather remembering commits so I can start a new branch there.

But I guess others might disagree.
-Peff
[1] Well, that and just piece of mind from knowing that "branch -d" is
    not totally unrecoverable. Specifically, if we kept deleted reflogs
    around, it would be safe(r) to turn on auto-prune on fetch, the lack
    of which is something that seems to confuse new users.
Previous: Junio C HamanoNext: Casey Dahlin
Message 20 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.