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

Re: Keeping reflogs on branch deletion

From
Nicolas Pitre <nico@cam.org>
Date
Feb 14, 2008, 15:00 UTC
Message-ID
<alpine.LFD.1.00.0802140945520.2732@xanadu.home>
In-Reply-To
<20080214140152.GT27535@lavos.net>
On Thu, 14 Feb 2008, Brian Downing wrote:
Show 16 quoted lines
> On Wed, Feb 13, 2008 at 07:43:21PM -0800, Junio C Hamano wrote:
> > People often mistake that the safety of "branch -d" is to not
> > lose the commit (i.e. not making it unreachable), but that is
> > not the case.  That safety already exists in HEAD reflogs.
> > 
> > The "branch -d" safety is about not losing the particular point.
> > The information we really are trying to protect is "this branch
> > points at _that commit_", which is just as important if not
> > more.
> 
> This actually brings up something I've been intending to ask.
> 
> When deleting a branch, is there any reason we can't add a deletion
> entry into the reflog and keep the reflog around?  This would seem to be
> a lot safer; I know I've been burned by expecting the reflog safety net
> to be there, and surprised that it's not when I've deleted a branch.
No.  That would only accumulate dead reflog files in the repository.

And as Junio said above, the "HEAD" reflog contains everything you moved to, including detached heads, and of course branch heads that might now be deleted. You can easily retrieve a deleted branch head from there.

For example, in my 'git log -g HEAD' output, I have:
|commit 40aab8119f38c622f58d8e612e7a632eb1f3ded2 
|Reflog: HEAD@{2} (Nicolas Pitre <nico@cam.org>) 
|Reflog message: checkout: moving from next to master

If I accidentally deleted my 'next' branch, I can retrieve it with HEAD@{3} which is the position HEAD was pointing to before moving away from 'next'. So, doing 'git branch next HEAD@{3}' would restore it.

Nicolas
Previous: Brian DowningNext: Johannes Schindelin
Message 7 of 15 in “A couple branch questions”
  1. Jay SoffianFeb 14, 2008
  2. David SymondsFeb 14, 2008
  3. Bill LearFeb 14, 2008
  4. David SymondsFeb 14, 2008
  5. Junio C HamanoFeb 14, 2008
  6. Keeping reflogs on branch deletionBrian Downing, Feb 14, 2008
  7. Nicolas PitreFeb 14, 2008
  8. Johannes SchindelinFeb 14, 2008
  9. Jeff KingFeb 14, 2008
  10. Nicolas PitreFeb 14, 2008
  11. Jeff KingFeb 14, 2008
  12. Nicolas PitreFeb 14, 2008
  13. Jeff KingFeb 14, 2008
  14. Wincent ColaiutaFeb 14, 2008
  15. Jakub NarebskiFeb 14, 2008

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.