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

Re: More Beginning Git Questions

From
Ttactical <a5158017@nepwk.com>
Date
Sep 26, 2011, 00:56 UTC
Message-ID
<1aec7c1qq0n56.sxybjnsj6ngr$.dlg@40tude.net>
In-Reply-To
<20110926003447.GG10955@localhost.localdomain>
Konstantin Khomoutov wrote:
Show 12 quoted lines
>>>> From what I read, detached heads are subject to garbage collection.
>>>  
>>> No, HEAD is protected against garbage collecting.  To be sure you
>>> should name a branch when switching branches, though reflog would
>>> protect you for 30 days (by default) even if you don't do that.
>> 
>> So Git doesn't really support anonymous branching as part of a normal
>> workflow.
> 
> I perceive a certain logical fallacy here: you cannot switch between
> anything anonymous because to switch, you should somehow identify
> something to switch to--a name in whatever sense we put into this word.

In Mercurial, you can just update to a particular changeset (and you identify that changeset by repository-local revision number or globally unique ID) and then commit again. The point is that there's no need to give a label to a head in Mercurial (although you can if you want to, using Mercurial bookmarks, which are basically the same as what Git uses).

Here's an example of anonymous branching:
    c:\test>hg init
    c:\test>echo test>foo
    c:\test>hg commit --addremove -m initial
    adding foo
    c:\test>echo first>>foo
    c:\test>hg commit -m first
    c:\test>hg log
    changeset:   1:3e895ec28d6c
    tag:         tip
    user:        tactical
    date:        Mon Sep 26 01:39:46 2011 +0100
    summary:     first
    changeset:   0:b51644bb3450
    user:        tactical
    date:        Mon Sep 26 01:39:40 2011 +0100
    summary:     initial
    c:\test>hg update 0
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
    c:\test>echo second>>foo
    c:\test>hg commit -m second
    created new head
    c:\test>hg glog
    @  changeset:   2:35c82a7e7de1
    |  tag:         tip
    |  parent:      0:b51644bb3450
    |  user:        tactical
    |  date:        Mon Sep 26 01:40:10 2011 +0100
    |  summary:     second
    |
    | o  changeset:   1:3e895ec28d6c
    |/   user:        tactical
    |    date:        Mon Sep 26 01:39:46 2011 +0100
    |    summary:     first
    |
    o  changeset:   0:b51644bb3450
       user:        tactical
       date:        Mon Sep 26 01:39:40 2011 +0100
       summary:     initial

I now have two anonymous branches, and these will never be garbage collected. I can easily update to either branch with "hg update 1" or "hg update 2" (or "hg update 0" again, if i want to create yet another anonymous branch).

> As I understand, by switching between branches in Mercurial you mean
> switching between directories with clones;
No.  Clones are a different topic.
Show 5 quoted lines
> As to branches, they do have names in Git but they are very loosely
> coupled with their names: tag a tip of some branch (to still have a
> handle on that tip commit) then delete that branch--there will be no
> traces of that branch's name left, the branch's name is not encoded in
> its history in any way.

Git branch names are basically the same as Mercurial bookmarks. The difference is that in Mercurial you don't *have* to use bookmarks.

Show 5 quoted lines
> The branch names is just a way to not mess with
> SHA-1 names of commits (and to have references to those commits to keep
> them out of consideration for garbage collection).
> Hence the idea to demand support for anonymous branches in Git's model
> is just unfounded.

I think it's simply a weakness of Git. There are zero problems with anonymous branching in Mercurial, and it's a very powerful and simple system.

Previous: Konstantin KhomoutovNext: Andrew Ardill
Message 17 of 24 in “More Beginning Git Questions”
  1. Jon ForrestSep 23, 2011
  2. Matthieu MoySep 23, 2011
  3. Jakub NarebskiSep 23, 2011
  4. Jon ForrestSep 23, 2011
  5. Mihamina RakotomandimbySep 23, 2011
  6. Jakub NarebskiSep 23, 2011
  7. tacticalSep 24, 2011
  8. Frans KlaverSep 24, 2011
  9. tacticalSep 24, 2011
  10. Seth RobertsonSep 24, 2011
  11. tacticalSep 25, 2011
  12. Jakub NarebskiSep 25, 2011
  13. tacticalSep 25, 2011
  14. Jakub NarebskiSep 25, 2011
  15. tacticalSep 25, 2011
  16. Konstantin KhomoutovSep 26, 2011
  17. tacticalSep 26, 2011
  18. Andrew ArdillSep 26, 2011
  19. tacticalSep 26, 2011
  20. Jakub NarebskiSep 26, 2011
  21. Jakub NarebskiSep 24, 2011
  22. tacticalSep 24, 2011
  23. Jakub NarebskiSep 25, 2011
  24. Junio C HamanoSep 23, 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.