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

Re: [PATCH] Proof-of-concept patch to remember what the detached HEAD was

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Oct 15, 2009, 16:29 UTC
Message-ID
<4AD74DE6.9010800@drmicha.warpmail.net>
In-Reply-To
<alpine.LNX.2.00.0910151054190.32515@iabervon.org>
Daniel Barkalow venit, vidit, dixit 15.10.2009 17:36:
Show 44 quoted lines
> On Thu, 15 Oct 2009, James Pickens wrote:
> 
>> On Wed, Oct 14, 2009 at 4:09 PM, Jeff King <peff@peff.net> wrote:
>>> That makes the most sense to me. If "git checkout" could write metadata
>>> into HEAD (or into DETACH_HEAD, as in Daniel's patch), then checkout
>>> could record an "ok to commit" bit. And could also be used to change it
>>> after the fact. E.g.:
>>>
>>>  $ git checkout --detach=commit origin/master
>>>  $ git commit ;# should be ok
>>>
>>>  $ git checkout --detach=examine origin/master
>>>  $ git commit ;# complain
>>>  $ git checkout --detach=commit HEAD
>>>  $ git commit ;# ok
>>>
>>> I guess something like "rebase" should detach with "ok to commit", since
>>> it is planning on attaching the commits later. I'm not sure about "git
>>> bisect". I guess probably it should be "not ok to commit" to be on the
>>> safe side, and then somebody can "git checkout --detach=commit" if they
>>> want to.
>>
>> How about not detaching the head at all if the user checks out any ref, and
>> reject commits if he checked out a tag or remote branch.  For example:
>>
>> $ git checkout origin/master
>> $ git status
>> # On branch origin/master
>> $ git commit ;# complain
>>
>> $ git checkout v1.0.1
>> $ git status
>> # On tag v1.0.1
>> $ git commit ;# complain
>>
>> $ git checkout v1.0.1^0 ;# detach
>> $ git commit ;# ok
>>
>> I think this would help the newbies and wouldn't cost the experts too much.
>> Checking out anything other than a plain ref would still detach the head, and
>> commits on a detached head would still be allowed.
> 
> I think reducing users' exposure to the "detached HEAD" state would just 
> make it take longer for them to find that state familiar.

Yep. Which is why I keep suggesting that git clone does not create any local branches at all ;)

Show 5 quoted lines
> It's not like the concept is actually very difficult or unusual. CVS has 
> it as "cvs checkout -r <something>" or "cvs checkout -D <something>"; SVN 
> has it as "svn checkout -r <something>". It was weird and scary in CVS if 
> you did it (it was "sticky tags", and you had to find a different option 
> to get back to normal), but SVN is easier ("svn checkout -r HEAD").
svn up -r HEAD
Show 6 quoted lines
> I think the description used in CVS and SVN (and, I think, others) is that 
> you're not at the HEAD revision. I think they both account for the state 
> where you've checked out the revision by number that's the latest 
> revision, but you still can't grow the branch because you can't 
> simultaneously stay on r1000 (as requested explicitly) and add a new 
> commit.

I'd say the fundamental difference is that in CVS and SVN, there is always only one "tip", which they call HEAD. This is also why revision numbers make sense.

In git and hg there can be many tips (branch heads) from which to grow the DAG. Heck, you can grow a new one from any commit ;)

Show 6 quoted lines
> So maybe the right explanation is:
> 
> $ git checkout master; git branch
> * master
> $ git checkout origin/master; git branch
> * origin/master (not at head)

Ouch, please don't. HEAD has a completely different meaning in git. I know you know, of course.

Show 12 quoted lines
> $ git checkout 123cafe^5; git branch
> * 123cafe^5 (not at head)
> $ git checkout HEAD^2; git branch
> * 123cafe^5^2
> $ git commit; git branch
> * (temporary branch)
> 
> Then we can say that one way that git is different from SVN is that all 
> branches of other repositories are read-only, and you can't be at the 
> head when you're on them (because the head of those branches are in 
> different repositories); instead you grow the history locally, and you 
> tell the remote branch to adopt your history.

You can change your refs/remotes/origin/master, of course, it's just by convention (for a good reason) that git treats them as read-only, and porc. respects that.

git's branches are simply completely different, they're movable tags, and I think that's one point new users *have* to grok. Once they're over this then even detached heads are a natural thing.

Show 7 quoted lines
>> Perhaps as an additional safety feature, Git could refuse to switch away 
>> from a detached head if the head isn't reachable from any ref
> 
> As far as I know, people don't actually seem to lose stuff this way. In 
> part, that's because they get scared before they get there; in part, 
> that's because they just don't think to go there; and in part, we tell 
> them how to recover stuff at that point (using the ref log or the sha1).
Maybe we just don't scare them enough yet :)
Michael
Previous: Daniel BarkalowNext: Nicolas Pitre
Message 39 of 93 in “Proof-of-concept patch to remember what the detached HEAD was”
  1. Proof-of-concept patch to remember what the detached HEAD wasDaniel Barkalow, Oct 14, 2009
  2. Junio C HamanoOct 14, 2009
  3. Jeff KingOct 14, 2009
  4. Johannes SchindelinOct 14, 2009
  5. Jeff KingOct 14, 2009
  6. Junio C HamanoOct 14, 2009
  7. Jeff KingOct 14, 2009
  8. Daniel BarkalowOct 14, 2009
  9. Jay SoffianOct 14, 2009
  10. Daniel BarkalowOct 14, 2009
  11. Nicolas PitreOct 14, 2009
  12. Daniel BarkalowOct 14, 2009
  13. Junio C HamanoOct 14, 2009
  14. Nicolas PitreOct 14, 2009
  15. Junio C HamanoOct 14, 2009
  16. Jeff KingOct 14, 2009
  17. Nicolas PitreOct 14, 2009
  18. Junio C HamanoOct 15, 2009
  19. Jeff KingOct 15, 2009
  20. Nicolas PitreOct 15, 2009
  21. Jeff KingOct 15, 2009
  22. Johannes SchindelinOct 16, 2009
  23. Nicolas PitreOct 16, 2009
  24. Johannes SchindelinOct 16, 2009
  25. Nicolas PitreOct 16, 2009
  26. Junio C HamanoOct 16, 2009
  27. Sean EstabrooksOct 17, 2009
  28. Johannes SchindelinOct 26, 2009
  29. Nanako ShiraishiOct 27, 2009
  30. Making Git easy to use -- without RTFM, was Re: [PATCH] Proof-of-concept patch to remember what the detached HEAD wasJohannes Schindelin, Oct 27, 2009
  31. Avery PennarunOct 27, 2009
  32. Johannes SchindelinOct 16, 2009
  33. Junio C HamanoOct 16, 2009
  34. James PickensOct 15, 2009
  35. Jakub NarebskiOct 15, 2009
  36. Björn SteinbrinkOct 15, 2009
  37. Nicolas PitreOct 15, 2009
  38. Daniel BarkalowOct 15, 2009
  39. Michael J GruberOct 15, 2009
  40. Nicolas PitreOct 15, 2009
  41. Daniel BarkalowOct 15, 2009
  42. Thomas RastOct 15, 2009
  43. Nicolas PitreOct 15, 2009
  44. Junio C HamanoOct 15, 2009
  45. Jeff KingOct 15, 2009
  46. Junio C HamanoOct 15, 2009
  47. Junio C HamanoOct 15, 2009
  48. Nicolas PitreOct 15, 2009
  49. James PickensOct 15, 2009
  50. Nicolas PitreOct 16, 2009
  51. Johannes SchindelinOct 16, 2009
  52. Björn SteinbrinkOct 16, 2009
  53. Jeff KingOct 15, 2009
  54. Jeff KingOct 15, 2009
  55. Björn SteinbrinkOct 16, 2009
  56. Daniel BarkalowOct 16, 2009
  57. Björn SteinbrinkOct 16, 2009
  58. Nicolas PitreOct 16, 2009
  59. Daniel BarkalowOct 15, 2009
  60. Junio C HamanoOct 15, 2009
  61. Daniel BarkalowOct 15, 2009
  62. Nicolas PitreOct 15, 2009
  63. Julian PhillipsOct 16, 2009
  64. Björn SteinbrinkOct 16, 2009
  65. Julian PhillipsOct 16, 2009
  66. Daniel BarkalowOct 16, 2009
  67. Junio C HamanoOct 16, 2009
  68. Julian PhillipsOct 16, 2009
  69. Nicolas PitreOct 16, 2009
  70. Julian PhillipsOct 17, 2009
  71. Björn SteinbrinkOct 17, 2009
  72. Julian PhillipsOct 17, 2009
  73. Björn SteinbrinkOct 17, 2009
  74. Julian PhillipsOct 17, 2009
  75. Junio C HamanoOct 16, 2009
  76. Julian PhillipsOct 17, 2009
  77. Junio C HamanoOct 17, 2009
  78. Julian PhillipsOct 17, 2009
  79. Björn SteinbrinkOct 17, 2009
  80. Junio C HamanoOct 17, 2009
  81. Björn SteinbrinkOct 17, 2009
  82. Junio C HamanoOct 17, 2009
  83. James PickensOct 17, 2009
  84. Björn SteinbrinkOct 17, 2009
  85. Junio C HamanoOct 18, 2009
  86. Björn SteinbrinkOct 19, 2009
  87. Julian PhillipsOct 17, 2009
  88. Eric RaibleOct 14, 2009
  89. Christoph BartoschekOct 16, 2009
  90. Junio C HamanoOct 17, 2009
  91. Björn SteinbrinkOct 17, 2009
  92. Junio C HamanoOct 17, 2009
  93. Daniel BarkalowOct 17, 2009

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.