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

Re: PATCH: improve git switch documentation

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 1, 2021, 14:58 UTC
Message-ID
<xmqqh7hersgp.fsf@gitster.g>
In-Reply-To
<b80bf908-0c31-2b3a-6d6c-1a3fba5b2334@mfriebe.de>
Martin <git@mfriebe.de> writes:
> Anyway, can we agree, that there are people who (mistakenly)
> use/understand "branch" as including the objects?
> Enough people to call it a "common mistake".
> If so, then we should not ignore this.

I do not think it is a mistake at all. In a history where the branch B points at commit Z, we do say the branch contains commits Z and Y and we do say the branch does not contain commits X or W, for example.

                 W---X
                /
        ---o---V---Y---Z
                       ^ we're here (branch B)

This is even true if the user is not yet familiar with the "snapshots" view of the world (which is based on "the objects"), but has the "changes" view of the world. The branch has the change that took Y to Z and the change that took V to Y, but it does not have the change that took W to X or the change that took V to W.

> With this use of "branch" in mind, (re-)creating an existing
> branch on a new startpoint, does to the inexperienced user read
> like a rebase. It recreates all the commits.

If I understand you correctly, the confusion your hypothetical newbie would have is caused by the word "start-point" in

	git branch -f <branch-name> <start-point>

That is, if we repoint the branch that is currently at Z to point at X with "git branch -f B X", it is possible to imagine that we build more history on top of "X" simply because "X" is called "start-point", i.e. we start at X and do something more.

And _your_ particular hypothetical user would imagine that that something more is to replay Y and Z on top.

But I find two problems with the proposed solution to solve that confusion.

 * Replaying Y and Z on top of X is not the only possible way to
   build "more" history on top of "start-point" that is X.  It is,
   for example, entirely plausible to look at the remote-tracking
   branch of B and rebuild the history missing from there on top of
   X, just like your version of confusion rebuilt the history
   missing from the tip of old B on top of X.  Saying "Z and Y will
   not be replayed on top of X after resetting the tip of the branch
   to X" may help _your_ version of confusion, but not other
   confusion.
 * In general, when an explanation in the documentation says that
   a command does A, it shouldn't have to say "the command does A
   but does not do B or C on top of that".

I think the source of the confusion is the <start point>. It does not change what the explanation wants to say at all if we changed it to <end point>. It is where the branch's tip ends up to be after "git branch -f" (or "git switch -C") finishes, so it might even be technically more correct.

The only reason why we use <start point> is purely historical. We used that phrase from the very beginning. The explanation did not consider the use of "gir branch -f" is the *end* of the world. It intended the user to use "gir branch [-f]" to start or restart a branch as the first step of many other things the user will do to build a history on the branch, and that is the reason why the word "start" is used.

Perhaps along the lines of the attached patch would be an improvement without adding "we do not do B, we do not do C, we do not do anything else we do not say we do in this documentation".

Note that the following is *not* meant to be a full illustration; there are many leftover <start-point> in these pages after this patch gets applied that need to be adjusted, if we were to go this route.

 Documentation/git-branch.txt |  4 ++--
 Documentation/git-switch.txt | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)
diff --git c/Documentation/git-branch.txt w/Documentation/git-branch.txt
index 94dc9a54f2..5e6a32da04 100644
--- c/Documentation/git-branch.txt
+++ w/Documentation/git-branch.txt
@@ -16,7 +16,7 @@ SYNOPSIS
 	[--points-at <object>] [--format=<format>]
 	[(-r | --remotes) | (-a | --all)]
 	[--list] [<pattern>...]
-'git branch' [--track | --no-track] [-f] <branchname> [<start-point>]
+'git branch' [--track | --no-track] [-f] <branchname> [<commit>]
 'git branch' (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
 'git branch' --unset-upstream [<branchname>]
 'git branch' (-m | -M) [<oldbranch>] <newbranch>
@@ -115,7 +115,7 @@ OPTIONS
 
 -f::
 --force::
-	Reset <branchname> to <startpoint>, even if <branchname> exists
+	Reset <branchname> to <commit>, even if <branchname> exists
 	already. Without `-f`, 'git branch' refuses to change an existing branch.
 	In combination with `-d` (or `--delete`), allow deleting the
 	branch irrespective of its merged status. In combination with
diff --git c/Documentation/git-switch.txt w/Documentation/git-switch.txt
index 5c438cd505..c8ea86d385 100644
--- c/Documentation/git-switch.txt
+++ w/Documentation/git-switch.txt
@@ -9,8 +9,8 @@ SYNOPSIS
 --------
 [verse]
 'git switch' [<options>] [--no-guess] <branch>
-'git switch' [<options>] --detach [<start-point>]
-'git switch' [<options>] (-c|-C) <new-branch> [<start-point>]
+'git switch' [<options>] --detach [<commit>]
+'git switch' [<options>] (-c|-C) <new-branch> [<commit>]
 'git switch' [<options>] --orphan <new-branch>
 
 DESCRIPTION
@@ -39,9 +39,9 @@ OPTIONS
 <new-branch>::
 	Name for the new branch.
 
-<start-point>::
-	The starting point for the new branch. Specifying a
-	`<start-point>` allows you to create a branch based on some
+<commit>::
+	The commit pointed at by the new branch. Specifying a
+	`<commit>` allows you to create a branch based on some
 	other point in history than where HEAD currently points. (Or,
 	in the case of `--detach`, allows you to inspect and detach
 	from some other point.)
@@ -59,7 +59,7 @@ out at most one of `A` and `B`, in which case it defaults to `HEAD`.
 -c <new-branch>::
 --create <new-branch>::
 	Create a new branch named `<new-branch>` starting at
-	`<start-point>` before switching to the branch. This is a
+	`<commit>` before switching to the branch. This is a
 	convenient shortcut for:
 +
 ------------
@@ -70,7 +70,7 @@ $ git switch <new-branch>
 -C <new-branch>::
 --force-create <new-branch>::
 	Similar to `--create` except that if `<new-branch>` already
-	exists, it will be reset to `<start-point>`. This is a
+	exists, it will be reset to `<commit>`. This is a
 	convenient shortcut for:
 +
 ------------
Previous: Felipe ContrerasNext: Martin
Message 88 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.