From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id F324E20248 for ; Fri, 8 Mar 2019 09:58:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726422AbfCHJ6y (ORCPT ); Fri, 8 Mar 2019 04:58:54 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43155 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726337AbfCHJ6y (ORCPT ); Fri, 8 Mar 2019 04:58:54 -0500 Received: by mail-pf1-f195.google.com with SMTP id q17so13785409pfh.10 for ; Fri, 08 Mar 2019 01:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aEllCt7W1UeEokkWTZCMOe9fdBCEdssaQLh8PVXHvnU=; b=FSsvJQTKrEH0Kr3itk0UHtpGa03OO0oWdgiDhC5g3ztjvA20bzKv3ZDT3dAuAroMTt 20pvEn/XbWckGRgnqE2J2/p90rgEf74a5xPAT8g3H1oNiB5h2jkHwCiw5itbTrWlHOWO 62cFEU+UugjV3nvpwg1bcxzXbX4EAhuSZyFXbzkRN67x/xR80X8YPWCgjptjDNUIfYrh PGTlqWw8+nf6WMzR7PqDjTe4v8fqL8yB9poi93TMVDgOD11sAILtkGQ4VMQFip+iCbGI 8jiwHJVN//udj15k9G/eInvHQclH6RqQ+npNOYDjuI+kuVC8S9/brVIZckNb+Spto73y jkFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aEllCt7W1UeEokkWTZCMOe9fdBCEdssaQLh8PVXHvnU=; b=r6hwA3NSxD97Z05BM5GrCxjZEzcxOwKcLOJ2KLvrBm1aU4TMyDxSW84QIsFMHD/QKW 2QzM0ObUhFdpcz6YpajJE6/fcv6GC0tHSosmBi6qKt/HisFFh0LoTNB7C5rY95tmnldz Vdjts5g1WwGG6riTFSOfvgOU5wWOAJ8ff1E6C/2/q3IPsQ9YKYXW5kIKYVvzssBWbTeC KmXHkW0vDrvObNBB/6NMRp3gc9jC9avGINg5TrAbG1Ht/jWUcCedVFDfjzoNi/Q8lQar 1N8nZsLxvQkzpO1g9leeUHuXYH9rlBaZVenvN0fWdcvTzUjAlwq5HwnM4qN9g3scLUhy jlpw== X-Gm-Message-State: APjAAAXiMVIRb4QlZYdbHZrE2HkPyMFW6o93vT63lVqak3uwfT7CZfF1 ROUlamr6dnmUAEj81C67iYw= X-Google-Smtp-Source: APXvYqw1KkMB5gfxvAZk7+opSmbvnIrfkwkloAKhBHSe300vFkY3DoNZ82hrxwlqmQz9J2IOGfeJLA== X-Received: by 2002:a63:e101:: with SMTP id z1mr16060403pgh.190.1552039132661; Fri, 08 Mar 2019 01:58:52 -0800 (PST) Received: from ash ([171.226.148.85]) by smtp.gmail.com with ESMTPSA id d188sm12960109pfg.98.2019.03.08.01.58.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Mar 2019 01:58:52 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Fri, 08 Mar 2019 16:58:48 +0700 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: pclouds@gmail.com Cc: git@vger.kernel.org, gitster@pobox.com, sunshine@sunshineco.com, szeder.dev@gmail.com Subject: [PATCH v3 10/21] checkout: split part of it to new command 'switch' Date: Fri, 8 Mar 2019 16:57:41 +0700 Message-Id: <20190308095752.8574-11-pclouds@gmail.com> X-Mailer: git-send-email 2.21.0.rc1.337.gdf7f8d0522 In-Reply-To: <20190308095752.8574-1-pclouds@gmail.com> References: <20190208090401.14793-1-pclouds@gmail.com> <20190308095752.8574-1-pclouds@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "git checkout" doing too many things is a source of confusion for many users (and it even bites old timers sometimes). To remedy that, the command will be split into two new ones: switch and something-to-checkout-paths. The good old "git checkout" command is still here and will be until all (or most of users) are sick of it. See the new man page for the final design of switch. The actual implementation though is still pretty much the same as "git checkout" and not completely aligned with the man page. Following patches will adjust their behavior to match the man page. --- .gitignore | 1 + Documentation/config/advice.txt | 13 +- Documentation/config/branch.txt | 4 +- Documentation/config/checkout.txt | 9 +- Documentation/config/diff.txt | 3 +- Documentation/git-checkout.txt | 4 + Documentation/git-switch.txt | 259 ++++++++++++++++++++++++++++++ Documentation/gitattributes.txt | 3 +- Documentation/githooks.txt | 8 +- Makefile | 1 + builtin.h | 1 + builtin/checkout.c | 60 +++++-- command-list.txt | 1 + git.c | 1 + 14 files changed, 341 insertions(+), 27 deletions(-) create mode 100644 Documentation/git-switch.txt diff --git a/.gitignore b/.gitignore index 7374587f9d..c687b92b1c 100644 --- a/.gitignore +++ b/.gitignore @@ -167,6 +167,7 @@ /git-submodule /git-submodule--helper /git-svn +/git-switch /git-symbolic-ref /git-tag /git-unpack-file diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index 88620429ea..239d479506 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -42,7 +42,8 @@ advice.*:: state in the output of linkgit:git-status[1], in the template shown when writing commit messages in linkgit:git-commit[1], and in the help message shown - by linkgit:git-checkout[1] when switching branch. + by linkgit:git-switch[1] or + linkgit:git-checkout[1] when switching branch. statusUoption:: Advise to consider using the `-u` option to linkgit:git-status[1] when the command takes more than 2 seconds to enumerate untracked @@ -62,12 +63,14 @@ advice.*:: your information is guessed from the system username and domain name. detachedHead:: - Advice shown when you used linkgit:git-checkout[1] to - move to the detach HEAD state, to instruct how to create - a local branch after the fact. + Advice shown when you used + linkgit:git-switch[1] or linkgit:git-checkout[1] + to move to the detach HEAD state, to instruct how to + create a local branch after the fact. checkoutAmbiguousRemoteBranchName:: Advice shown when the argument to - linkgit:git-checkout[1] ambiguously resolves to a + linkgit:git-checkout[1] and linkgit:git-switch[1] + ambiguously resolves to a remote tracking branch on more than one remote in situations where an unambiguous argument would have otherwise caused a remote-tracking branch to be diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt index 019d60ede2..8050466159 100644 --- a/Documentation/config/branch.txt +++ b/Documentation/config/branch.txt @@ -1,5 +1,5 @@ branch.autoSetupMerge:: - Tells 'git branch' and 'git checkout' to set up new branches + Tells 'git branch', 'git switch' and 'git checkout' to set up new branches so that linkgit:git-pull[1] will appropriately merge from the starting point branch. Note that even if this option is not set, this behavior can be chosen per-branch using the `--track` @@ -11,7 +11,7 @@ branch.autoSetupMerge:: branch. This option defaults to true. branch.autoSetupRebase:: - When a new branch is created with 'git branch' or 'git checkout' + When a new branch is created with 'git branch', 'git switch' or 'git checkout' that tracks another branch, this variable tells Git to set up pull to rebase instead of merge (see "branch..rebase"). When `never`, rebase is never automatically set to true. diff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt index c4118fa196..d6872ffa83 100644 --- a/Documentation/config/checkout.txt +++ b/Documentation/config/checkout.txt @@ -1,5 +1,6 @@ checkout.defaultRemote:: - When you run 'git checkout ' and only have one + When you run 'git checkout ' + or 'git switch ' and only have one remote, it may implicitly fall back on checking out and tracking e.g. 'origin/'. This stops working as soon as you have more than one remote with a '' @@ -8,8 +9,10 @@ checkout.defaultRemote:: disambiguation. The typical use-case is to set this to `origin`. + -Currently this is used by linkgit:git-checkout[1] when 'git checkout -' will checkout the '' branch on another remote, +Currently this is used by linkgit:git-switch[1] and +linkgit:git-checkout[1] when 'git checkout ' +or 'git switch ' +will checkout the '' branch on another remote, and by linkgit:git-worktree[1] when 'git worktree add' refers to a remote branch. This setting might be used for other checkout-like commands or functionality in the future. diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt index e48bb987d7..b3b304ee12 100644 --- a/Documentation/config/diff.txt +++ b/Documentation/config/diff.txt @@ -78,7 +78,8 @@ diff.external:: diff.ignoreSubmodules:: Sets the default value of --ignore-submodules. Note that this affects only 'git diff' Porcelain, and not lower level 'diff' - commands such as 'git diff-files'. 'git checkout' also honors + commands such as 'git diff-files'. 'git checkout' + and 'git switch' also honor this setting when reporting uncommitted changes. Setting it to 'all' disables the submodule summary normally shown by 'git commit' and 'git status' when `status.submoduleSummary` is set unless it is diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 1b9d689933..ac355dc3f3 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -560,6 +560,10 @@ $ edit frotz $ git add frotz ------------ +SEE ALSO +-------- +linkgit:git-switch[1] + GIT --- Part of the linkgit:git[1] suite diff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt new file mode 100644 index 0000000000..ff60ba69fb --- /dev/null +++ b/Documentation/git-switch.txt @@ -0,0 +1,259 @@ +git-switch(1) +============= + +NAME +---- +git-switch - Switch branches + +SYNOPSIS +-------- +[verse] +'git switch' [] [--guess] +'git switch' [] --detach [] +'git switch' [] (-c|-C|--orphan) [] + +DESCRIPTION +----------- +Switch to a specified branch. The working tree and the index are +updated to match the branch. All new commits will be added to the tip +of this branch. + +Optionally a new branch could be created with either `-c` or `-C`, or +detach the working tree from any branch with `--detach`, along with +switching. + +Switching branches does not require a clean index and working tree +(i.e. no differences compared to 'HEAD'). The operation is aborted +however if the switch leads to loss of local changes, unless told +otherwise. + +OPTIONS +------- +:: + Branch to switch to. + +:: + Name for the new branch. + +:: + The name of a commit at which to switch to before creating a + new branch or detach from. ++ +You can use the `"@{-N}"` syntax to refer to the N-th last +branch/commit switched to "git switch" or "git checkout" +operation. You may also specify `-` which is synonymous to `"@{-1}"`. ++ +As a special case, you may use `"A...B"` as a shortcut for the merge +base of `A` and `B` if there is exactly one merge base. You can leave +out at most one of `A` and `B`, in which case it defaults to `HEAD`. + +-c :: +--create :: + Create a new branch named `` starting at + `` before switching to the branch. This is a + convenient shortcut for: ++ +------------ +$ git branch +$ git switch +------------ + +-C :: +--force-create :: + Similar to `--create` except that if `` already + exists, it will be reset to ``. This is a + convenient shortcut for: ++ +------------ +$ git branch -f +$ git switch +------------ + +-d:: +--detach:: + Switch to a commit for inspection and discardable + experiments. See the "DETACHED HEAD" section in + linkgit:git-checkout[1] for details. + +-g:: +--guess:: + If `` is not found but there does exist a tracking + branch in exactly one remote (call it ``) with a + matching name, treat as equivalent to ++ +------------ +$ git switch -c --track / +------------ ++ +If the branch exists in multiple remotes and one of them is named by +the `checkout.defaultRemote` configuration variable, we'll use that +one for the purposes of disambiguation, even if the `` isn't +unique across all remotes. Set it to e.g. `checkout.defaultRemote=origin` +to always checkout remote branches from there if `` is +ambiguous but exists on the 'origin' remote. See also +`checkout.defaultRemote` in linkgit:git-config[1]. + +-q:: +--quiet:: + Quiet, suppress feedback messages. + +-f:: +--force:: + Proceed even if the index or the working tree differs from + HEAD. Both the index and working tree are restored to match + the switching target. This is used to throw away local + changes. + +--progress:: +--no-progress:: + Progress status is reported on the standard error stream + by default when it is attached to a terminal, unless `--quiet` + is specified. This flag enables progress reporting even if not + attached to a terminal, regardless of `--quiet`. + +-t:: +--track:: + When creating a new branch, set up "upstream" configuration. + `-c` is implied. See "--track" in linkgit:git-branch[1] for + details. ++ +If no `-c` option is given, the name of the new branch will be derived +from the remote-tracking branch, by looking at the local part of the +refspec configured for the corresponding remote, and then stripping +the initial part up to the "*". This would tell us to use "hack" as +the local branch when branching off of "origin/hack" (or +"remotes/origin/hack", or even "refs/remotes/origin/hack"). If the +given name has no slash, or the above guessing results in an empty +name, the guessing is aborted. You can explicitly give a name with +`-c` in such a case. + +--no-track:: + Do not set up "upstream" configuration, even if the + branch.autoSetupMerge configuration variable is true. + +-m:: +--merge:: + If you have local modifications to one or more files that are + different between the current branch and the branch to which + you are switching, the command refuses to switch branches in + order to preserve your modifications in context. However, + with this option, a three-way merge between the current + branch, your working tree contents, and the new branch is + done, and you will be on the new branch. ++ +When a merge conflict happens, the index entries for conflicting +paths are left unmerged, and you need to resolve the conflicts +and mark the resolved paths with `git add` (or `git rm` if the merge +should result in deletion of the path). + +--conflict=