diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-11-23 15:00:31 +0900 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-12-13 07:48:17 -0800 |
commit | b23285a921a84c3b83d9aaca31afedf290c59254 (patch) | |
tree | 9d60e7089e73328124c9b6603547e3dd6769ac3f /Documentation/git-switch.txt | |
parent | 9263c40a0a0c299db59b8a64e87b95026a28812a (diff) | |
download | git-b23285a921a84c3b83d9aaca31afedf290c59254.tar.gz |
checkout: forbid "-B <branch>" from touching a branch used elsewhere
"git checkout -B <branch> [<start-point>]", being a "forced" version
of "-b", switches to the <branch>, after optionally resetting its
tip to the <start-point>, even if the <branch> is in use in another
worktree, which is somewhat unexpected.
Protect the <branch> using the same logic that forbids "git checkout
<branch>" from touching a branch that is in use elsewhere.
This is a breaking change that may deserve backward compatibliity
warning in the Release Notes. The "--ignore-other-worktrees" option
can be used as an escape hatch if the finger memory of existing
users depend on the current behaviour of "-B".
Reported-by: Willem Verstraeten <willem.verstraeten@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'Documentation/git-switch.txt')
-rw-r--r-- | Documentation/git-switch.txt | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt index c60fc9c138..6137421ede 100644 --- a/Documentation/git-switch.txt +++ b/Documentation/git-switch.txt @@ -59,13 +59,18 @@ 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 - convenient shortcut for: + `<start-point>` before switching to the branch. This is the + transactional equivalent of + ------------ $ git branch <new-branch> $ git switch <new-branch> ------------ ++ +that is to say, the branch is not reset/created unless "git switch" is +successful (e.g., when the branch is in use in another worktree, not +just the current branch stays the same, but the branch is not reset to +the start-point, either). -C <new-branch>:: --force-create <new-branch>:: |