From: Christian Couder Date: Fri, 10 Dec 2021 08:34:43 GMT Subject: Re: [PATCH 2/2] checkout: introduce "--to-branch" option Message-ID: In-Reply-To: <254b352e31029d8151eb6a974fdf8c127340cf79.1639117329.git.gitgitgadget@gmail.com> On Fri, Dec 10, 2021 at 7:22 AM ZheNing Hu via GitGitGadget wrote: > > From: ZheNing Hu > > When we want checkout to a branch (e.g. dev1) which reference > to a commit, but sometimes we only remember the tag (e.g. v1.1) > on it, we will use `git checkout v1.1` to find the commit first, > git will be in the state of deatching HEAD, so we have to search the s/deatching/detached/ It's possible, and likely faster, to use something like `git log -1 v1.1` or `git show ` to see which branches point to the tag or commit, as the branches are added as decoration to the output. > branches on the commit and checkout the branch we perfer. This will s/perfer/prefer/ > be a bit cumbersome. > > Introduce "--to-branch" option, `git checkout --to-branch ` > and `git checkout --to-branch ` will search all branches > and find a unique branch reference to the commit (or the commit which > the tag reference to) and checkout to it. If the commit have more s/have/has/ > than one branches, it will report error "here are more than one s/branches/branch/ > branch on commit". Maybe reporting something like "more than one branch point to commit XXX" would be a bit better. > Signed-off-by: ZheNing Hu > --- > Documentation/git-checkout.txt | 8 +++- > builtin/checkout.c | 33 +++++++++++++ > t/t2018-checkout-branch.sh | 85 ++++++++++++++++++++++++++++++++++ > t/t9902-completion.sh | 1 + > 4 files changed, 126 insertions(+), 1 deletion(-) > > diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt > index d473c9bf387..2a240699fd9 100644 > --- a/Documentation/git-checkout.txt > +++ b/Documentation/git-checkout.txt > @@ -10,7 +10,7 @@ SYNOPSIS > [verse] > 'git checkout' [-q] [-f] [-m] [] > 'git checkout' [-q] [-f] [-m] --detach [] > -'git checkout' [-q] [-f] [-m] [--detach] > +'git checkout' [-q] [-f] [-m] [--detach] [-w|--to-branch] It's a bit strange that --detach can be used along with the new option, as the purpose of the new option is to not detach. It makes one wonder what happens when both --detach and --to-branch are used. I wonder if all the following lines: git checkout [-q] [-f] [-m] [] git checkout [-q] [-f] [-m] --detach [] git checkout [-q] [-f] [-m] [--detach] could be replaced with just: git checkout [-q] [-f] [-m] [--detach|--to-branch] > 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] ] [] > 'git checkout' [-f|--ours|--theirs|-m|--conflict=