All of lore.kernel.org
 help / color / mirror / Atom feed
* feedback/idea about "switch -C" force create
@ 2021-06-29 11:11 Martin
  2021-06-29 11:33 ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 4+ messages in thread
From: Martin @ 2021-06-29 11:11 UTC (permalink / raw)
  To: git

First of all, my first post, hope it's the correct place.

I've been using the new git switch for some time, and also I have helped 
people new to git.
When people are new to git, I try to avoid introducing them to commands 
that can loose them commits (such as git reset).

"git switch" however has to be on the list of commands that new user 
have to learn early, but unfortunately when used with "-C" it may cause 
the loss of commits.
I am aware, it is a force option. But I still think it may be better if 
it could emit a warning, or even reject the job.

Reasons:
1) Newcomers may not be aware of the extend of such a force at all. 
Newcomers may not expect loss of commits, on such an elementary command.

2) People aware that it is a "force" may not be aware of the extend of 
the force, because there are either up to 2 actions forced.

Action 1)
The move of the branch is forced.
- That means, the info which commit was on the top of the branch before 
will be lost.
- Also the move may affect push-ability without "force"

Action 2)
The commit may be lost (except for the reflog, but many less experienced 
people do not know that).
This loss is dependent on other factors. It may or may not happen.
Because it does not always happen, people may not expect it.

As a result:
- A user could believe the force is for the effect on the branch, and be 
unaware of the loss of commit
- A user (ever experienced) could opt for the force in the good belief 
that their commits are held by other branches, when maybe they are not.

Therefore I believe, it would be best, if   git -C  branch new-location
would give an error, if this will lose commits.

There could be
- a git config to  toggle this
- an additional command line option to extend the force to drop commits


I would like to know if that idea might in general be acceptable at all.
If so, where it could or should be made as a feature request 
(unfortunately I wont be able to provide a patch myself)


On top, I would propose that the documentation of the current behaviour 
should be made more clear.

https://git-scm.com/docs/git-switch about -C / --force-create
>   Similar to --create except that if <new-branch> already exists, it 
> will be reset to <start-point>. This is a convenient shortcut for:
>
>   $ git branch -f <new-branch>
>   $ git switch <new-branch>
While the word "force" is in the option itself, the description does not 
explain what is forced, or what effects this may have.
Instead it only refers the user to study another option.
I believe the documentation should state directly
- commits currently in part of that branch may be lost [under certain 
circumstances]

and maybe, but less important
- the old location of the branch will be lost



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-29 15:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-29 11:11 feedback/idea about "switch -C" force create Martin
2021-06-29 11:33 ` Ævar Arnfjörð Bjarmason
2021-06-29 13:44   ` Martin
2021-06-29 15:01   ` Martin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.