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
Junio C Hamano <gitster@pobox.com>
Date
Oct 15, 2009, 21:54 UTC
Message-ID
<7v1vl42uid.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20091015212632.GA13180@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 20 quoted lines
> On Thu, Oct 15, 2009 at 12:52:55PM -0700, Junio C Hamano wrote:
>
>> I like James's suggestion to allow us to store refs other than refs/heads/
>> in HEAD to denote this state, and keep commit and reset from updating such
>> a ref through updating HEAD.
>
> Didn't we already consider and reject this the first time around? For
> example, this thread has a ton of stuff about how we shouldn't prevent
> people from making commits on the wandering state:
>
>   http://thread.gmane.org/gmane.comp.version-control.git/35777/focus=35835
>
> And here's me even advocating this exact strategy (and I'm sure I didn't
> think of it; it's probably discussed elsewhere, too):
>
>   http://thread.gmane.org/gmane.comp.version-control.git/35777/focus=35858
>
> Not that I am not necessarily complaining, but I just hope this decision
> is "with new-found knowledge we are revisiting this decision" and not
> "we totally forgot about what came before".
Maybe we are reading different messages in the same message.
My understanding of James's suggestion is:
 (1) "git checkout $token" makes HEAD point at the refname dwim_ref()
     expands $token to, iff dwim_ref() is happy, and otherwise detaches
     HEAD;
 (2) "git commit" (and other things like "git reset HEAD^" that updates
     underlying ref thru updates to HEAD when HEAD is a symref) rejects
     when HEAD points at a ref outside refs/heads/, but works when HEAD
     points at a local branch, or when HEAD is detached.
As a consequence:
    $ git checkout v1.6.5      ;# does not detach, cannot update
    $ git symbolic-ref HEAD
    refs/tags/v1.6.5
    $ git checkout origin/next ;# ditto
    $ git symbolic-ref HEAD
    refs/remotes/origin/next

These are often done by sightseers, and we can add instructions to fork and record upon an attempt to "git commit".

As a bonus, we get Daniel's extra information for detached HEAD for free, as we can just read HEAD and learn what it points at. We need to design what "git branch" should say in this case.

This is backward incompatible, and makes what experts are used to do slightly cumbersome to spell, i.e.

    $ git checkout v1.6.5^0      ;# detaches and can commit
    $ git checkout origin/next^0 ;# ditto
    $ git checkout $(git merge-base master sp/smart-http) ;# ditto

These detach, and I can apply the updates series to the same base as the previous round on an unnamed branch.

So in other words, the semantics for detached HEAD case does not change at all. We never forbid committing or resetting while on detached HEAD, as it is meant to be an easy way to get an unnamed throw-away state that is not even worth coming up with a unique temporary branch name, and I do not think the above contradicts with what was said in 35835.

We used to have only two states on HEAD: either on a local branch or detached. James is introducing another state: on a ref that is not a local branch.

As that is useful for common sightseer tasks, we can afford to forbid committing or updating for safety and we do not have to worry about hurting the established usefulness of how detached HEAD works.

One drawback is that you cannot be in this sightseeing state without having a ref. You can have "look-but-not-touch" checkout on origin/next or origin/master, but you cannot sightsee the parent of origin/next the same way (it would detach). I do not know if it is a big deal, though.

If it is very important to support:
    $ git checkout --look-but-not-touch origin/next^

then James's approach would not be very useful, as we do have to detach HEAD and implement the "do not touch" logic for detached HEAD state anyway, so we might just use the same logic we would use for origin/next^ when checking out origin/next itself.

Previous: Jeff KingNext: Junio C Hamano
Message 46 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.