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

Re: PATCH: improve git switch documentation

From
Matt Rogers <mattr94@gmail.com>
Date
Jul 1, 2021, 00:06 UTC
Message-ID
<CAOjrSZuoD5-5FeRXmFPbRxFptyv_x-G3quFqCptvCX_XY9mSyw@mail.gmail.com>
In-Reply-To
<7870a0ad-8fa1-9dbd-1978-1f44ec6970c5@mfriebe.de>
On Wed, Jun 30, 2021 at 4:50 AM Martin <git@mfriebe.de> wrote:
Show 43 quoted lines
>
> On 30/06/2021 00:39, Junio C Hamano wrote:
> > Martin <git@mfriebe.de> writes:
> >
> >> My text may indeed have lacked clarity. I was trying to emphasize to
> >> hard, that this
> >> command's "force" enables 2 actions that may both not be
> >> wanted. Usually if one applies
> >> "force" to a command only one such action is expected, or at least I
> >> would only expect the one.
> > Oh, I do agree wholeheartedly if two things are forced at the same
> > time, things can become confusing.
> >
> > But the thing is, there are no such "two things are forced at once"
> > in this case.  That is why I emphasized, in my response to you, that
> > "switch -C <newbranch>" does not touch working tree, so "ok, the
> > switch stops because it requires some working tree files with
> > changes clobbered, and I can force it to make it happen" is not
> > involved.  If it were, then it becomes fuzzy if --force is allowing
> > an existing branch getting overwritten, or allowing a modification
> > in a working tree file getting discarded, or both.
> Well, yes and no. IMHO.
>
>  From what I have seen, there are main 2 cases people use -C.
>
> 1) By accident, meaning to do something else. Most often meaning to do a
> rebase.
> I.e. some one who is new, desperately to fix "branch has diverged".
> For this, those people need to be made aware that -C does not move the
> commits.
>
> 2) Intentional, when the branch to be re-created points to a commit,
> which is hold
>   by further branches. So no commit becomes unreachable.
> In that case it is not a documentation issue. It is a, how can I enable
> the re-create,
> but have git warn me, if I somehow misjudged the situation and on other
> branch
> has the commit. That is, when I see this as 2 individually actions, out
> of which I want
> to allow only one. Anyway that is not documentation, and I did sent
> another mail.
>

I just want to point out that my usual use-case for using -C (or checkout -f, but the usage is similar enough for this discussion) is when I want to create a temporary branch with a generic name (e.g. tmp) and I haven't cleaned out my unused branches in a while. If I find myself having branched off the wrong commit and wanting to move work I already committed, the user should be looking to use either rebase or merge for that.

I would also consider that using a command literally called "switch --force-create" does not seem like the obvious first choice for "My history is different than that history".

Show 23 quoted lines
> And yes, for the documentation, it *should* be clear that, removing a
> branch, removes the
> commits on it.
> But then it must be said, that the branch is first removed. That is not
> currently the case.
> I proposed an alternate text to that nature in my last mail.
>
> For the rest, it is a matter of opinion.
> When I think a new user may read this, I believe such consequential
> implications should
> be mention rather explicit.
> But, if your view (the view of the git team is) a new user should have
> read up far enough
> to be fully aware of those consequence, then so be it.
>
> As per my previous mail, then maybe
>        Force creating a branch, means that an existing branch of the
> same name is removed.
>       A new branch is created at the specified <start point>. The
> new branch will not
>       necessarily have all the commits that the existing branch used to
> have.
>
I think the current documentations usage of "reset" in
    Similar to --create except that if <new-branch> already exists, it
will be reset to <start-point>.

Is pretty clear about what happens, although it does rely on users being familiar with the semantics of "resetting" a la git reset. I think rephrasing it in terms of branch removal/creation actually obfuscates the matter.

Show 10 quoted lines
> Well, if one creates a new feature branch, and instead of forking of
> master, one forks of some
> random other branch. Then one can immediately re-create it at the
> original intended
> branch point. No commits on the branch, none lost.
> But teach that to a newbie, and they may have committed to the branch,
> before they
> realize they forked at the wrong point. If the then do -C those commit
> will be gone. (well, yes the reflog).
>

I don't think that this is a great usage of switch -C. generally I teach people to look at the state of their repository via `git log --graph --oneline --all` and then decide whether they need to rebase their work or if they can just reset onto the branch they want to.

-- 
Matthew Rogers
Previous: Felipe ContrerasNext: Martin
Message 94 of 103 in “PATCH: improve git switch documentation”
  1. MartinJun 29, 2021
  2. Junio C HamanoJun 29, 2021
  3. MartinJun 29, 2021
  4. Junio C HamanoJun 29, 2021
  5. MartinJun 30, 2021
  6. Junio C HamanoJun 30, 2021
  7. MartinJul 1, 2021
  8. Sergey OrganovJul 1, 2021
  9. Felipe ContrerasJul 7, 2021
  10. Sergey OrganovJul 7, 2021
  11. What actually is a branch?Felipe Contreras, Jul 7, 2021
  12. Sergey OrganovJul 7, 2021
  13. MartinJul 7, 2021
  14. Felipe ContrerasJul 8, 2021
  15. MartinJul 8, 2021
  16. Felipe ContrerasJul 8, 2021
  17. MartinJul 8, 2021
  18. Felipe ContrerasJul 8, 2021
  19. MartinJul 8, 2021
  20. Felipe ContrerasJul 9, 2021
  21. MartinJul 9, 2021
  22. Felipe ContrerasJul 9, 2021
  23. switch requires --detach [[Re: What actually is a branch]]Martin, Jul 9, 2021
  24. Felipe ContrerasJul 9, 2021
  25. Randall S. BeckerJul 9, 2021
  26. Felipe ContrerasJul 9, 2021
  27. MartinJul 9, 2021
  28. Sergey OrganovJul 10, 2021
  29. Felipe ContrerasJul 10, 2021
  30. MartinJul 9, 2021
  31. Felipe ContrerasJul 9, 2021
  32. MartinJul 9, 2021
  33. Felipe ContrerasJul 9, 2021
  34. MartinJul 9, 2021
  35. Felipe ContrerasJul 10, 2021
  36. MartinJul 10, 2021
  37. Felipe ContrerasJul 10, 2021
  38. Naming the --forec option [[Re: PATCH: improve git switch documentation]]Martin, Jul 10, 2021
  39. Felipe ContrerasJul 10, 2021
  40. MartinJul 11, 2021
  41. Felipe ContrerasJul 12, 2021
  42. MartinJul 10, 2021
  43. Felipe ContrerasJul 10, 2021
  44. MartinJul 11, 2021
  45. Sergey OrganovJul 11, 2021
  46. Felipe ContrerasJul 12, 2021
  47. MartinJul 12, 2021
  48. Felipe ContrerasJul 12, 2021
  49. MartinJul 12, 2021
  50. Felipe ContrerasJul 12, 2021
  51. Sergey OrganovJul 11, 2021
  52. MartinJul 11, 2021
  53. Sergey OrganovJul 11, 2021
  54. MartinJul 11, 2021
  55. Felipe ContrerasJul 12, 2021
  56. Sergey OrganovJul 10, 2021
  57. Bagas SanjayaJul 10, 2021
  58. MartinJul 10, 2021
  59. Sergey OrganovJul 10, 2021
  60. Felipe ContrerasJul 10, 2021
  61. Sergey OrganovJul 11, 2021
  62. MartinJul 11, 2021
  63. Sergey OrganovJul 11, 2021
  64. MartinJul 11, 2021
  65. Sergey OrganovJul 11, 2021
  66. Sergey OrganovJul 11, 2021
  67. Kerry, RichardJul 12, 2021
  68. Sergey OrganovJul 12, 2021
  69. Felipe ContrerasJul 12, 2021
  70. Felipe ContrerasJul 12, 2021
  71. MartinJul 12, 2021
  72. Felipe ContrerasJul 12, 2021
  73. Sergey OrganovJul 12, 2021
  74. Felipe ContrerasJul 12, 2021
  75. MartinJul 13, 2021
  76. Felipe ContrerasJul 10, 2021
  77. Felipe ContrerasJul 10, 2021
  78. Sergey OrganovJul 11, 2021
  79. Felipe ContrerasJul 12, 2021
  80. Sergey OrganovJul 13, 2021
  81. Felipe ContrerasJul 13, 2021
  82. Sergey OrganovJul 14, 2021
  83. Felipe ContrerasJul 14, 2021
  84. Sergey OrganovJul 14, 2021
  85. Felipe ContrerasJul 8, 2021
  86. Sergey OrganovJul 8, 2021
  87. Felipe ContrerasJul 8, 2021
  88. Junio C HamanoJul 1, 2021
  89. MartinJul 1, 2021
  90. Sergey OrganovJul 1, 2021
  91. Felipe ContrerasJul 7, 2021
  92. Felipe ContrerasJul 7, 2021
  93. Felipe ContrerasJul 7, 2021
  94. Matt RogersJul 1, 2021
  95. MartinJul 13, 2021
  96. Felipe ContrerasJul 13, 2021
  97. MartinJul 16, 2021
  98. MartinJul 16, 2021
  99. Felipe ContrerasJul 16, 2021
  100. MartinJul 17, 2021
  101. MartinJul 17, 2021
  102. MartinJul 17, 2021
  103. Felipe ContrerasJul 19, 2021

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.