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

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

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Dec 7, 2010, 20:55 UTC
Message-ID
<20101207205526.GA25008@burratino>
In-Reply-To
<7vfwu9pbyj.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
> "git log -g HEAD"
> keeps track of what was at the tip of HEAD, be it pointing at a branch or
> pointing diretly at a commit in a detached state, no?
Yes.
1. Imagine I have an interesting branch and delete it:
	$ git branch interesting $(lots of hard work)
	$ git branch -D interesting

Oops. If I want to recover that branch, I may have a lot of digging to do in the HEAD reflog. It may not be there are all. Your patch mitigates that by allowing a simple "I didn't mean that" command.

	$ git branch --undelete interesting
2. Great.  Another way to lose a line of development, as Casey
mentioned, is to not give it a branch name in the first place:
	$ git checkout HEAD^0
	...
	$ git checkout something-else

Oops. Well, not so bad. If I want to recover my old work, I can simply use

	$ git checkout HEAD@{1}
3. Now suppose I was not paying attention and made the mistake
from (1) or (2) a week ago and didn't realize it.  Now I want to
get back that code.

If it was situation (1), I can remember the name of the branch and do

	$ git branch --undelete interesting

No problem [1]. If it was situation (2), I need to dig through the HEAD reflog. As Jeff explained, it is possible to script something up to help organize the search. I think Casey was suggesting doing that work at HEAD-reattachment time instead, so you could do

	$ git branch --undelete-detached-head=old-head

to recover the last line of development made without a branch; my response was that if this ends up frequently being useful then I suspect something is wrong with the workflow.

Hoping that is clearer, Jonathan

[1] as long as the branch name was not reused
Previous: Junio C HamanoNext: Jeff King
Message 27 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.