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
Björn Steinbrink <b.steinbrink@gmx.de>
Date
Oct 16, 2009, 05:03 UTC
Message-ID
<20091016050312.GB9233@atjola.homenet>
In-Reply-To
<885649360910151647v27a15334x63fe3b6f5035dbd2@mail.gmail.com>
On 2009.10.15 16:47:57 -0700, James Pickens wrote:
Show 23 quoted lines
> On Thu, Oct 15, 2009 at 3:08 PM, Junio C Hamano <gitster@pobox.com> wrote:
> > Junio C Hamano <gitster@pobox.com> writes:
> >
> >>     $ git checkout origin/next ;# ditto
> >>     $ git symbolic-ref HEAD
> >>     refs/remotes/origin/next
> >
> > Ok, after reading Daniel's message to remind us that "git fetch" after
> > this will get us into trouble, I agree that detaching HEAD is inevitable.
> 
> Some people liked the idea, so let's not give up just yet.  Here are a few
> things Git could do when a fetch wants to update the currently checked out
> branch:
> 
> 1. Refuse the fetch.
> 2. Update the ref, leaving the user with a work tree and index that don't
>    match their HEAD.
> 3. Detach the HEAD, then update the ref.
> 4. Update the ref, then check it out.
> 
> Option 1 is ok, as long as the "next step" is not too complicated.  It's no
> good if the user has to checkout a different branch, then fetch, then
> checkout the original branch again.

Not good. It makes "git fetch; git log ..origin/foo" impossible. And that's IMHO a very useful thing for people that just want to follow things and look at what happens.

> Option 2 is crap.
Agreed.
> Option 3 seems reasonable, but it might be just as scary/confusing to
> newbies as the current behavior, so I don't think it should be the default.

Doesn't seem very good to me. The idea was to stop people from accidently getting on a detached HEAD, if common operations like "fetch" now suddenly detach HEAD, that's _worse_ than before. And for a single-branch remote, even "git pull" may detach HEAD then:

git init; git remote add -f -t master origin git://... git checkout origin/master *wait* git pull # Will work, as the fetch refspec is not a glob

But that "pull" does: git fetch origin refs/heads/master:refs/remotes/origin/master

Which detaches HEAD before merging/fast-forwarding.
Bad.

And seeing that the requests for "clone just a single branch" seem to increase in #git, I guess that such non-globbing refspecs for remote.origin.fetch might become more common in the future.

> Option 4 also seems reasonable, but you run into problems if the user had
> changed the index or work tree.  In that case Git could do 'checkout
> --merge' automatically.  This option is also less "pure" since it lets 'git
> fetch' modify the index and work tree.

Same as for option 1, it kills "git fetch; git log ..origin/foo". And that would basically turn "fetch" into a hypothetical "pull --reset". That's IMHO better done in a separate command.

Show 5 quoted lines
> So how about this:
> * 'git fetch' refuses the fetch by default.
> * 'git fetch --detach' detaches HEAD, then updates the ref
> * 'git pull' detaches HEAD, updates the ref, then checks out the new ref
>   with --merge.

"fetch --detach" doesn't feel right to me. Wrong class of commands to have such an option. And I'm not sure about adding a third mode to "pull" (besides "merge" and "rebase") that only triggers for special cases. Again, I'd prefer a separate command.

If we store "where did I come from" instead of just "where am I" in HEAD when detached, those problems don't seem to show up (but just storing that information correctly seems hard enough, see the other mail I wrote a few minutes ago).

"git fetch" just updates the remote tracking branch, you stay at where you are, "git log ..origin/foo" keeps working. It could give a special hint that you might want to use "git checkout origin/foo" or "git new-command" to update your working tree to the newest version, when your working tree is based upon an old version of that remote tracking branch.

And "git pull" might perform a fast-forward automatically (figuring out the right remote from the extra info in HEAD), but refuse to do merges (if upstream has been rewritten), pointing the user to "git checkout" or "git new-command". (Interestingly, "pull --rebase" wouldn't suffer from such history rewriting, as it looks at the reflog for the remote tracking branch, but I guess a working "git pull --rebase" while "git pull" fails is bound to cause major user confusion).

"git new-command" could act like "svn up", doing a fetch and a "checkout --merge <remote_tracking_branch>" to just get the user up-to-date keeping local uncommitted modifications. I can't tell why, but my feeling is that this should be a new command, and not part of pull, as said above.

Björn
Previous: Johannes SchindelinNext: Jeff King
Message 52 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.