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: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.6 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, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id AE1D11F953 for ; Fri, 10 Dec 2021 08:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238536AbhLJIia (ORCPT ); Fri, 10 Dec 2021 03:38:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235992AbhLJIia (ORCPT ); Fri, 10 Dec 2021 03:38:30 -0500 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 491C1C061746 for ; Fri, 10 Dec 2021 00:34:55 -0800 (PST) Received: by mail-yb1-xb29.google.com with SMTP id d10so19685022ybe.3 for ; Fri, 10 Dec 2021 00:34:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GDvpWcZGGpGgRQehOxwqP1XtwBkXoQP/zH+jM3855sg=; b=ECIlyelGLsFPE/MdgDWuiAScTg/9CV1MS9a7xIxXi5igB86UHFCbXYjkig0NLIWCCl A8qooDOVWdW0EnynXcAMAZ2BoxBgEikNBNgx0Ow03idGPTh/Gk2VpUwad6CB9l3FvSpm NpsYcqFiZ5mLlO43k/aA1hQLxh7VGgbqeOzZ6gg6TkbouryYX2+/SGQV5fQql5nLyzzn e8QvR13BoyppKk+/4tcH8DT/CqXVwfYAa23iwj9yWMqj7iNgLkAaSJuyCHJlJoIvejTH 1NhBq1plZRsuxoJcseIlzlKic/aV0Is49grEvVk9huAX7buUi/ulTYJ+ziJm0wOK6ZyO jfkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GDvpWcZGGpGgRQehOxwqP1XtwBkXoQP/zH+jM3855sg=; b=k1HWzC2in/m+tZHSkWqSUaOlUxoleR95Mq9nUltgOZ/Ss2hhmet3HLdfTvDFrlVenL gH/z9K0lrs4neEysfgUTBP280s3Rnn6JfGga/BiWL7vu6YZUnMernsqnlFiL8b0+1PT5 kEu+eb8Agwj3Wh5+gOIfIDMaXNbHnZio9Xs6bZIo5LtqNvnV+97xVtx/PL9kyxXTi+WY PW/YY0PYXFuTcuyZg2GXNddXR5MoENms4NY8sjMJqiCPk987TFtxoNnNlHX+0OzAxLoq NsDmGTC0uyfpjFgfmC9A779uEHMQDATGhRwEu2ohf7kb7TOHi3Tf3fPp+Uf2FyLxlwFU NQMw== X-Gm-Message-State: AOAM53025jmRjdMK5ylixwVcm9prqM+XabZ909crYK+d50qjJc9L2qx3 aBfqifhiFb+k4dZqfO11gSa66GNO9C5ApoeFU9E= X-Google-Smtp-Source: ABdhPJxZT1dgp860UBjDcxcTmdq+kehWZHvibYI0L26A4eTupEkQI5HKYt3EdTGE5ASU3V67RkYehCf0KIMof+fUH1w= X-Received: by 2002:a25:8609:: with SMTP id y9mr12423760ybk.50.1639125294393; Fri, 10 Dec 2021 00:34:54 -0800 (PST) MIME-Version: 1.0 References: <254b352e31029d8151eb6a974fdf8c127340cf79.1639117329.git.gitgitgadget@gmail.com> In-Reply-To: <254b352e31029d8151eb6a974fdf8c127340cf79.1639117329.git.gitgitgadget@gmail.com> From: Christian Couder Date: Fri, 10 Dec 2021 09:34:43 +0100 Message-ID: Subject: Re: [PATCH 2/2] checkout: introduce "--to-branch" option To: ZheNing Hu via GitGitGadget Cc: git , Junio C Hamano , Hariom Verma , "brian m. carlson" , =?UTF-8?B?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= , =?UTF-8?B?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Eric Sunshine , ZheNing Hu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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=