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

Re: [PATCH] Docs: git checkout --orphan: `root commit' and `branch head'

From
Michael Witten <mfwitten@gmail.com>
Date
Sep 28, 2011, 04:37 UTC
Message-ID
<CAMOZ1Bv3b-EkvCrRYw=_s9SXQw+v9wgQbGab7hsz+Wx+tndhJw@mail.gmail.com>
In-Reply-To
<CAG+J_DxzcuYiffm6XVX-RQSxeMwy4Yi7CdhCdddAN=xRyJ2b5Q@mail.gmail.com>
On Wed, Sep 28, 2011 at 04:04, Jay Soffian <jaysoffian@gmail.com> wrote:
Show 22 quoted lines
> On Tue, Sep 27, 2011 at 1:25 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Michael Witten <mfwitten@gmail.com> writes:
>>
>>> It seems like a more logical approach would be instead for "git
>>> commit" to take a "--root" option that would create a new root commit
>>> based on the current index and then point the current branch head to
>>> the new root commit. Thus:
>>>
>>>   $ git checkout -b new_branch old_branch
>>>   $ # Manipulate or not
>>>   $ git commit --root
>>>
>>> That's how people think.
>>
>> This may indeed be an improvement. I suspect that we'd need to think about
>> it a bit more, but it feels right (perhaps introduce this new option,
>> deprecate --orphan from the checkout, and then eventually remove it
>> sometime in 1.8.0 timeframe).
>
> Hrm, create new_branch just so you can immediately clobber its SHA1
> with the new commit that has no parents. That doesn't seem quite
> right.
The point is that users think about 2 things:
  * I need to create a root commit.
  * I need a branch head to point to that root commit,
    and I probably want a new branch head to do that.

My goal is to match the way people think; nobody thinks about the SHA1 when doing this task, and everybody thinks about creating a new branch head.

More to the point, how is it better that "checkout --orphan" sets up the working tree and index when the user is just going to obliterate them or alter them significantly?

> Imagine you use "git commit --root" by accident while on
> master, then you have to dig into your reflog?

What's wrong with, say, "git reset --hard ORIG_HEAD"? (note that ORIG_HEAD is already something understood by git).

Show 6 quoted lines
> But it's close. Maybe:
>
> $ git commit --new-root-branch=<name>
>
> Which creates <name> with the index as its sole commit and switches
> you to that branch? That doesn't feel quite right either.
The "git commit" command shouldn't be canoodling the branch layer so intimately.
In fact, that's why I dislike:
  git checkout --orphan <branch_head>

The "--orphan" flag was no doubt added to "git checkout" because of there already existed:

  git checkout -b <branch_head>
However, that is only available as a convenience (that is, a hack) for:
  git branch <branch_head>
  git checkout <branch_head>

It seems to be an even larger hack that "git checkout" as been given so much control over setting the stage for not only the creation of a branch head, but also the nature of the ancestry of the *next* commit.

Previous: Jay SoffianNext: Michael J Gruber
Message 48 of 57 in “Can a git changeset be created with no parent”
  1. vra5107Sep 25, 2011
  2. Andreas EricssonSep 25, 2011
  3. Carlos Martín NietoSep 25, 2011
  4. Junio C HamanoSep 26, 2011
  5. Carlos Martín NietoSep 26, 2011
  6. Docs: git checkout --orphan: `root commit' and `branch head'Michael Witten, Sep 27, 2011
  7. Matthieu MoySep 27, 2011
  8. Docs: git checkout --orphan: `root commit' and `branch head'Michael Witten, Sep 27, 2011
  9. Matthieu MoySep 27, 2011
  10. Michael WittenSep 27, 2011
  11. Matthieu MoySep 27, 2011
  12. Michael WittenSep 27, 2011
  13. Philip OakleySep 27, 2011
  14. Docs: git checkout --orphan: `root commit' and `branch head'Michael Witten, Sep 28, 2011
  15. Junio C HamanoSep 28, 2011
  16. Michael WittenSep 29, 2011
  17. Docs: git checkout --orphan: Copyedit, and s/root commit/orphan branch/Michael Witten, Sep 29, 2011
  18. Michael WittenSep 29, 2011
  19. Philip OakleySep 29, 2011
  20. Junio C HamanoSep 29, 2011
  21. Michael WittenSep 29, 2011
  22. Documentation/git-checkout.txt: Explain --orphan without introducing an undefined "orphan branch"Junio C Hamano, Sep 29, 2011
  23. Michael WittenSep 29, 2011
  24. Phil HordSep 29, 2011
  25. Michael WittenSep 29, 2011
  26. Phil HordSep 29, 2011
  27. Michael WittenSep 29, 2011
  28. Michael J GruberSep 27, 2011
  29. Michael WittenSep 27, 2011
  30. Junio C HamanoSep 27, 2011
  31. Michael WittenSep 27, 2011
  32. Eric RaibleSep 27, 2011
  33. Philip OakleySep 27, 2011
  34. Jeff KingSep 27, 2011
  35. Michael WittenSep 27, 2011
  36. Jeff KingSep 27, 2011
  37. Michael WittenSep 27, 2011
  38. Junio C HamanoSep 28, 2011
  39. Michael WittenSep 28, 2011
  40. Matthieu MoySep 28, 2011
  41. Michael WittenSep 28, 2011
  42. Matthieu MoySep 28, 2011
  43. Michael WittenSep 28, 2011
  44. Matthieu MoySep 28, 2011
  45. Michael WittenSep 28, 2011
  46. Junio C HamanoSep 28, 2011
  47. Jay SoffianSep 28, 2011
  48. Michael WittenSep 28, 2011
  49. Michael J GruberSep 28, 2011
  50. Junio C HamanoSep 29, 2011
  51. Phil HordSep 29, 2011
  52. Michael WittenSep 29, 2011
  53. Michael WittenSep 29, 2011
  54. Junio C HamanoSep 29, 2011
  55. Michael WittenSep 30, 2011
  56. Junio C HamanoSep 30, 2011
  57. Michael WittenSep 29, 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.