From patchwork Wed Jan 30 09:48:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10788083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0D2D13BF for ; Wed, 30 Jan 2019 09:49:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA32A2DF2D for ; Wed, 30 Jan 2019 09:49:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE28E2DFA8; Wed, 30 Jan 2019 09:49:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E3BC2DF2D for ; Wed, 30 Jan 2019 09:49:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730505AbfA3JtS (ORCPT ); Wed, 30 Jan 2019 04:49:18 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:39842 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbfA3JtR (ORCPT ); Wed, 30 Jan 2019 04:49:17 -0500 Received: by mail-pf1-f195.google.com with SMTP id r136so11177689pfc.6 for ; Wed, 30 Jan 2019 01:49:16 -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=D4BWYFWctsZf/a9vQ/u6CZdbREnDd4iGqq76tkFTkwc=; b=efdRmyvB7wG6hOr3V93KYMAkv/jlqKc9eK82mpTIIo2cUl/8eVGeyIF+WleWN33K6S vY0BJIWsmhanA4/oXtF4PRLfBbEhij2WxZSEE5tKvLwNRi/Us5NtjCaqfEIe/9WfoppG zZfqHdbSW/mut69FvdH/kNzzHaclHPd3KhzEXbsR0nNW5dkK/htWYAjrW+u2kqXaTkWi e7LSUcswDmS/0OJ33NKJQeQe0jGFXbtNrjE6ODp+u6rfGeyZwxhMbSqULqwLGIjbQDxx WfK5zuQ37qHHQ2lQY+JyWJzgWep6N2n0Gz02lduPrd6LsIycXqFcJB0v4X7Em4Vu4CZy Rz5g== 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=D4BWYFWctsZf/a9vQ/u6CZdbREnDd4iGqq76tkFTkwc=; b=q5AeCdPQacAn2SbDxxJhC0YCGDTfpKHxBtc/JFSEshAlnBlkLV/QLxLgHnf6YvPBtB ZvwdG21v9yjy/9um22lIeoO4grLNVPfxMGPvhPbmYTsiu5/WthN5czEcn/rhLfheW76r OTrKXgqB5fNvNdqE7bpKDnula+9U31eSDMK0rpt2kwfC3XW6Q5+3i8+0rmG4OrLJqjSk yCn8+Th+Wmn/Q+umY5IPOUAjx4NPakF0A2yBxrLswcHEmrzFPVx+dlS7C5p/ZpLXHpeq CqkZyaQ9C3WDz8U9Fm8VoM9Iotaldisf8aJ1QqDr9pNiTfqx4rtiCCtIcgifvDoKincf u3Bg== X-Gm-Message-State: AJcUukcrt/oorqLY5x+IAeLom7L96bSbRzNvgd2CWWwCb5heweGvV5Bk 7XRPFumtaSSJClnIkoN43sfCYovl X-Google-Smtp-Source: ALg8bN5MkWyrdoBaM/lPnq8xgiB3aOB1RiirR/r5OBrvWHl6SLPqof+A+MMl7OwwrA3QjUTHofIZ4g== X-Received: by 2002:a65:560e:: with SMTP id l14mr26932335pgs.168.1548841755867; Wed, 30 Jan 2019 01:49:15 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id e86sm1756133pfb.6.2019.01.30.01.49.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 01:49:15 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Wed, 30 Jan 2019 16:49:11 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH 08/19] checkout: split part of it to new command switch Date: Wed, 30 Jan 2019 16:48:20 +0700 Message-Id: <20190130094831.10420-9-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.682.gd5861c6d90 In-Reply-To: <20190130094831.10420-1-pclouds@gmail.com> References: <20190130094831.10420-1-pclouds@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP "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. Signed-off-by: Nguyễn Thái Ngọc Duy --- .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 | 236 ++++++++++++++++++++++++++++++ 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, 318 insertions(+), 27 deletions(-) create mode 100644 Documentation/git-switch.txt diff --git a/.gitignore b/.gitignore index 0d77ea5894..8e2b89047f 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 73380a8d86..fc211eca58 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 9ac01f7967..31c6cbef19 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -556,6 +556,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..953c9747b2 --- /dev/null +++ b/Documentation/git-switch.txt @@ -0,0 +1,236 @@ +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 and update files in the working tree to +match it. Optionally a new branch could be created with either `-c` or +`-C`, or detach from any branch with `--detach`, along with switching. + +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 and start it at + ; see linkgit:git-branch[1] for details. + +-C :: +--force-create :: + Creates the branch and start it at ; + if it already exists, then reset it to . This is + equivalent to running "git branch" with "-f"; see + linkgit:git-branch[1] for details. + +-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. This is used to throw away local changes. + +--[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=