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.7 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,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 494881FA00 for ; Fri, 10 Dec 2021 06:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236968AbhLJGZt (ORCPT ); Fri, 10 Dec 2021 01:25:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236960AbhLJGZs (ORCPT ); Fri, 10 Dec 2021 01:25:48 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98D4AC061746 for ; Thu, 9 Dec 2021 22:22:13 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id q3so13231927wru.5 for ; Thu, 09 Dec 2021 22:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=AaMFAGuHyGmRJkNO/12RO83mwTwL2xBcBbb2UHD9ays=; b=Ww9PMQ8ucyX4nOW1ODt6h4Y7FFO2xKrfemxtYSrVkGfGytXsPMLvgCAQ4ZniK2yzmq d7QhFUFYyjqXVb/+AbPiq+zXF22RQQJwqSJuBgIFRyZWAxqmswkzXvQADvmOMoRoC60N 4S0mWD8LUcqZhkf7SjsZ0uv8aBBB1gOKpiK5e/TS+SZV8NV2od2bwZSK2nQZRHpPI0Gj J8qvKC2S3thIwcdRZ/smHF+nHA5BXXgQqgPW2Zqc6xXzw4QIsu6jOKsIRhjWyILqWobv XXGpa7oIhCTm8uxge/et9PdwmzGw1v4K/NmxQRrp59egAPe8MfX643d3D3BIzAiqqYcG B7ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=AaMFAGuHyGmRJkNO/12RO83mwTwL2xBcBbb2UHD9ays=; b=6IWDfQJgsMdQ3UbTrG7lm4/90QuTaszPz+M15Nzeokjo9hhwxfGUCYNbivhEBTRKua BzJTU/Sf6afQKrNVbfmjsPqse7ZoZuh31dIqEUO2zBpNdodOIFIg2TdGsNztVqthDlMy TfoPZ1Jrskrz4Hf2eebf40rpV5reTo8c2LADn4pu0IiD8iuU3MtpO7GCUsMH2Z2o/sG8 biO1V1lHDYl7V0MHkTbH6asnkz7TVwOTqJG9TAF5qli6fRDMxYbGgUtoPPuGBoPRAN5p Tu3BNtNINpHyZJxpbe5sS+IEZHayOt3eU98def+0+rdwYU7/OFDth38qXkzvTHYLBGuf 7IaQ== X-Gm-Message-State: AOAM533fvLc2+v+6vDywIOARfOgTXDJbTAIKo//TlW9UI+VsCy8xyl7W UXT0hubvPM+zDPUqSgeNojHhVEAPnTg= X-Google-Smtp-Source: ABdhPJxL6ck4Lxnyn49CijoxH+5MN2+cePzgteWYZ0ueZ2xK3xee1yzZf8sDwWXKm8Bb7YmEWm9HRA== X-Received: by 2002:adf:fb86:: with SMTP id a6mr11851834wrr.35.1639117332052; Thu, 09 Dec 2021 22:22:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d1sm1476759wrz.92.2021.12.09.22.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:22:11 -0800 (PST) Message-Id: <254b352e31029d8151eb6a974fdf8c127340cf79.1639117329.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "ZheNing Hu via GitGitGadget" Date: Fri, 10 Dec 2021 06:22:09 +0000 Subject: [PATCH 2/2] checkout: introduce "--to-branch" option Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Christian Couder , Hariom Verma , "brian m. carlson" , =?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?= Duy , =?UTF-8?Q?=C3=86var_Arnfj=C3=B6r=C3=B0?= Bjarmason , Eric Sunshine , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 branches on the commit and checkout the branch we perfer. This will 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 than one branches, it will report error "here are more than one branch on commit". 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] 'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] ] [] 'git checkout' [-f|--ours|--theirs|-m|--conflict=