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

Re: [PATCH] Detached HEAD (experimental)

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 9, 2007, 23:39 UTC
Message-ID
<20070109233948.GC30023@spearce.org>
In-Reply-To
<7vy7obj07k.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
> I do not want to think about the consequences of adding more
> cruft under .git/ directory.  For example, should PREV be
> noticed by fsck and prune?  What should various forms of
> 'git-reset' do with it?  How does it interact with 'git-bisect'?
I agree.  The reachability list for those is already starting to
get out of control, and the rules for making sure those files are
always in sync with every command is getting crazy.  Didn't we just
fix `git reset --hard` to throw away .git/MERGE_MSG?  That's been
a longstanding bug right there, and that's something that has been
in the tree for a loooooooong time.
 
Show 5 quoted lines
> Being able to test merge or even make commits without being on a
> branch is vastly useful.  It might or might not lead to anywhere
> even after you make a handful commits -- and I would imagine
> that it would be very handy to be able to be lazy and not having
> to decide if it is worth a new branch.
I agree.  I'm always creating and deleting `foof` because I need
someplace to work real quick.  Being able to work on a detached HEAD
would just slightly streamline the process, especially given that
`git checkout -b a-real-name` is readily available to move that
detached HEAD state into a real branch and continue on with it.
 
> If Carl wants to do a patch to teach
> 'git-commit' (and all other things that can create commits) not
> to do things from working in a detached HEAD

My concern here is to hit all of the corner cases. reset. bisect. am. rebase. merge. cherry-pick/revert. Did I get all of 'em? I'm not sure actually. ;-)

> It's tempting to forget about this whole "safety" business.
> Because we allow "reset --hard" and other forms of operations
> that can lose history if they were done while on a branch, only
> giving the safety to "git checkout" feels somewhat silly.

But isn't the --hard switch the safety valve here? And lets not forget that reflogs are enabled by default now so even a `reset --hard` on a real branch isn't a total loss (its only a loss for uncommitted files in the working directory).

But a detached HEAD has no reflog. Which means operations that update it in a non-fastforward way would orphan work. A subsequent gc/prune/repack might destroy it, unless an existing ref contains that previous commit.

> Which makes the "merge-base --check-ancestry" stuff I did last
> night pretty much unnecessary, but that's Ok.  It will find
> other uses.

Pity. It looked like it was a good change and would be useful here as a safety valve. Though based on what you said above I would think we'd actually want it in both checkout and reset (--soft and --hard versions).

-- 
Shawn.
Previous: Junio C HamanoNext: Linus Torvalds
Message 44 of 68 in “Detached HEAD (experimental)”
  1. Detached HEAD (experimental)Junio C Hamano, Jan 2, 2007
  2. Edgar ToernigJan 2, 2007
  3. Carl WorthJan 2, 2007
  4. Jakub NarebskiJan 2, 2007
  5. Carl WorthJan 3, 2007
  6. J. Bruce FieldsJan 6, 2007
  7. Alan ChandlerJan 6, 2007
  8. J. Bruce FieldsJan 6, 2007
  9. Junio C HamanoJan 2, 2007
  10. Carl WorthJan 2, 2007
  11. Junio C HamanoJan 3, 2007
  12. Junio C HamanoJan 8, 2007
  13. Jeff KingJan 8, 2007
  14. Junio C HamanoJan 9, 2007
  15. Carl WorthJan 9, 2007
  16. Junio C HamanoJan 9, 2007
  17. Carl WorthJan 9, 2007
  18. Shawn O. PearceJan 9, 2007
  19. Junio C HamanoJan 9, 2007
  20. 0/6 Expose in_merge_bases() via merge-base.Junio C Hamano, Jan 9, 2007
  21. Luben TuikovJan 9, 2007
  22. Jeff KingJan 9, 2007
  23. Junio C HamanoJan 9, 2007
  24. J. Bruce FieldsJan 9, 2007
  25. Carl WorthJan 9, 2007
  26. J. Bruce FieldsJan 9, 2007
  27. Shawn O. PearceJan 9, 2007
  28. Jakub NarebskiJan 10, 2007
  29. Shawn O. PearceJan 10, 2007
  30. J. Bruce FieldsJan 10, 2007
  31. Shawn O. PearceJan 10, 2007
  32. Nicolas PitreJan 10, 2007
  33. Junio C HamanoJan 10, 2007
  34. Shawn O. PearceJan 10, 2007
  35. Nicolas PitreJan 10, 2007
  36. Shawn O. PearceJan 10, 2007
  37. Jakub NarebskiJan 10, 2007
  38. Andreas EricssonJan 10, 2007
  39. Junio C HamanoJan 10, 2007
  40. Daniel BarkalowJan 10, 2007
  41. Andreas EricssonJan 11, 2007
  42. Junio C HamanoJan 10, 2007
  43. Junio C HamanoJan 9, 2007
  44. Shawn O. PearceJan 9, 2007
  45. Linus TorvaldsJan 9, 2007
  46. Junio C HamanoJan 10, 2007
  47. Shawn O. PearceJan 10, 2007
  48. Linus TorvaldsJan 10, 2007
  49. Carl WorthJan 10, 2007
  50. Junio C HamanoJan 10, 2007
  51. Andy ParkinsJan 10, 2007
  52. Shawn O. PearceJan 10, 2007
  53. Junio C HamanoJan 10, 2007
  54. Andy ParkinsJan 10, 2007
  55. Shawn O. PearceJan 10, 2007
  56. Junio C HamanoJan 10, 2007
  57. Jeff KingJan 10, 2007
  58. Junio C HamanoJan 11, 2007
  59. J. Bruce FieldsJan 11, 2007
  60. Jeff KingJan 3, 2007
  61. Jeff KingJan 3, 2007
  62. git-branch: show detached HEADLars Hjemli, Jan 2, 2007
  63. Shawn O. PearceJan 3, 2007
  64. Junio C HamanoJan 3, 2007
  65. Lars HjemliJan 3, 2007
  66. Junio C HamanoJan 3, 2007
  67. Junio C HamanoJan 3, 2007
  68. Lars HjemliJan 3, 2007

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.