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

Re: PATCH: improve git switch documentation

From
MMartin <git@mfriebe.de>
Date
Jun 30, 2021, 08:50 UTC
Message-ID
<7870a0ad-8fa1-9dbd-1978-1f44ec6970c5@mfriebe.de>
In-Reply-To
<xmqqpmw4uwh2.fsf@gitster.g>
On 30/06/2021 00:39, Junio C Hamano wrote:
Show 19 quoted lines
> 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.

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.
But without
      It therefore also means that commits from the old existing branch 
may be no longer reachable.
Show 17 quoted lines
>> The actions being, giving up the link to the commit that is the tip of
>> the branch; and
>> making commits unreachable.  (for an expert in git tightly linked
>> together, but not for everyone)
> Sorry, I do not quite see how the removing the reference to a commit
> (i.e. the commit C that used to be pointed at by the branch would no
> longer be pointed at by that branch---that is by definition what
> moving the branch to point at a different commit means) and the
> commit becoming not reachable from the reference (i.e. such a commit
> C may not be reachable from the branch---unless the new commit it
> points at happens to be a descendant of C) are not one and the same
> thing.  I do not think there is distinction between expert vs
> everyone else involved here at all.
>
> Can you give an example where one of the two holds while the other
> one does not?
>

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).

Personally (that may not be a common pattern), I have used two branches for one feature branch. One that holds the tip, and represents my local work. One that I move forward and backward on the branch, to run tests, and decide what I already want to push. Forward could be done by ff-merge, but backward not (it's reset, or switch -C).

--------- About your comment on changes in the worktree. In none of my examples do I have any changes in my worktree.

I know that when I just try to switch a branch, git switch will refuse to overwrite my changes. The doc for the -C section does not say if it will. That is something I actually would still need to check, and if -C in addition to forcing the branch, and consequently but only in some cases "making commits unreachable", does also overwrite working dir changes that would be yet one more "forced" action. That again not everyone may automatically be aware off.

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 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.