Thread (37 messages) flat view 37 messages, 4 authors, 2021-07-12

Re: PATCH: improve git switch documentation

From: Felipe Contreras <hidden>
Date: 2021-07-10 19:45:28

Martin wrote:
On 09/07/2021 19:41, Felipe Contreras wrote:
quoted
Martin wrote:
quoted
Well, that is the question as what the action is perceived.
I think the example is wrong, rather than the command.

-c / -C /-n / -N always *c*reate an *n*ew branch. (create and new really
are the same thing here)

But if the branch name Foo, is already used?
Well, it will still be a *new* branch being *created*.
To do that it has to remove the name from the old branch. (effectively
removing the old branch).
But it's not removing the name, it's merely changing the head.

I don't particularly mind having -C or -N, I just would not use them
because I like to be explicit. I don't use --new for something that
already exists.
But that comes down to the "what is a branch" discussion.

It is not creating a new branchname. But it is creating a new branch. 
And then the branchname refers to that new branch.

It changes head, base, and the entire content. That effectively makes it 
new.
Yes, it is a new branch, but the name doesn't change.
If you have a 10 year old car that you nicknamed "speedy", and I come 
along and I replace every part (every screw, every whatever...) with a 
brand new part, would you still call the result a 10 year old car (even 
if (or just because) you still use the nickname) ?
Yeah but you are entering into metaphysics of identity, see the Ship of
Theseus [1]. By that same logic why are you still called Martin if every
cell in your body wasn't there when you were originally born?

These thought experiments are interesting, but philosphers have discused
about this for thousands of years and the conclussion is still
undecided, so I don't think we'll come to a conclussion here.

Moreover, I don't even think it's relevant. We agree that the branch is
a different branch, we agree that the name doesn't change, and we agree
that the user doesn't want the name to change. We don't need to enter
into a philosophical discussion to see if the name *should* change.
Using "reset", it's similar. Except that human language is slopy.
If I play WOW, and I reset the game. Actually that is already wrong. I 
do not reset the game. It is still the same code, the same images.... I 
do reset my session or status. And after that, I will be in a new 
session, or have a new status.
Words mean whatever humans using those words intend them to mean. If
most people use the word "reset" in a certin way, that's what the word
means. Even if you have a good ontological reason why reset shouldn't be
used like that, it's used like that.
- "creating" the branch is "setting (up) the branch"
- "re-setting" is doing doing this (creation) again.
Resetting is not necesarilly creating again, it can mean setting up
again.
quoted
quoted
Nope it does not go away.

All this has done, is that it no longer is a "force" command.
So the last bit of warning has just gone.

And it still needs to be documented inside the "git switch" doc, rather
than forwarding the user do yet another doc.
Yes, but as I said: the documentation writes itself.

   -n <branch>, --new <branch>

     Creates a new branch.

   --reset <branch>

     Resets the branch to <head>.
And that still leaves it to the user to connect the dots, and come to 
the conclusion that the old branch is no longer holding his valued commits.
No. You can add all the explanation you want after "Resets the branch to
<head>.", but most of that explanation would be redundant, because as we
already agreed, there's no way to reset the head of a branch without
changing the branch.
quoted
quoted
So, I still ask:
- If "--force" to overwrite the work tree can clearly state that change
to files will be "thrown away".
- Then why can "force" re-using an existing branch name not do the same?
Because we would be forcing two things now. 
Which 2 things?

The worktree overwriting is *not* forced by -C

   git switch -C b1 b2
   git checkout -B b1 b2

both give an error if the worktree has changed files.

This is only about what happens to the branch.

I.e we force the branchname to point to our new branch.
And that means the branchname no longe points to the old branch, and the 
old branch therefore is removed.
It seems your proposal is to make `git switch -c --force b1 b2` be the same as
`git switch -C b1 b2`, but that would also make it the same as
`git switch -C --force b1 b2`. Therefore it would be forcing two things.

Or is your proposal something else?

[1] https://en.wikipedia.org/wiki/Ship_of_Theseus

-- 
Felipe Contreras
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help