From patchwork Thu Mar 28 22:17:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10876035 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 589181390 for ; Thu, 28 Mar 2019 22:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 383DE28E65 for ; Thu, 28 Mar 2019 22:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2754A28E6C; Thu, 28 Mar 2019 22:17:55 +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 3CBBC28E65 for ; Thu, 28 Mar 2019 22:17:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728190AbfC1WRu (ORCPT ); Thu, 28 Mar 2019 18:17:50 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:36930 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726472AbfC1WRu (ORCPT ); Thu, 28 Mar 2019 18:17:50 -0400 Received: by mail-pl1-f194.google.com with SMTP id q6so20414pll.4 for ; Thu, 28 Mar 2019 15:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=erEStCQelhZeo3p36wM1K2sS6toP+umuv0lUL6QIz98=; b=BXvNwrhcLsPeQVXK54JR7+bAyIO/zguD40M9oQUOLNTtGwfhOEvhM61ooYPHnyCVjB d1fKO+RU75i7vlXIoteaAw3TwKGZKZWCghiZD9baA8WqCYT6A2NfWeUCiDBoEaO2zrI9 uRrSrP/ls3bHdWJWdyzGLodHglMhHaTbzFuRlvZW1wpvzlyw1ih16o3g7YCT56Iv5XyA mSIlE9LMm/jxqIKfeRD6FzI7B4tw/8uoMo1+i/gc86cs69peXKYb0lHNEA1an+eMbDQG f+Vv0itn1ZtaWd/zrck9NcKT0ILIKR+8Axp1dybAgiHmvULvdnYfNFVAYvEhM41jCWGh 1slA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=erEStCQelhZeo3p36wM1K2sS6toP+umuv0lUL6QIz98=; b=na1YwGMBiNXMZPLcEUis5kBG34K7WT2rHx1AznQ80s5cgAcqGWfCGN/JZRNdqdO2Bn Y84JJ5YKq5YE8CQSN67NU2K+u3f8dR13lFtVdk//VZq9x6/ETu4gun6g04m3b6VqpNeK Xh3/xQd1Z1GX3MbI1Lw8KEw3/P4LubONgtSaDjRNd+O8SMCGNu43XuHtrBWeGfV+2NA1 eiykffcgehihmquuDinagMRKt8k0tgw5qbGuMZYn2gzICZnYRqhY7EWAGozwlvvsI/yR aK+9W9JftIwlwLreX85zdw/z8uhgiPQ5k2IfkzxnbLPtatAqkkhKE73RF4kyBL/kFPRI 8e0A== X-Gm-Message-State: APjAAAUCDJ09TtjCBBvqxbzCH/taiVvsQnjNghGkB9FiyzMfUO2byJl5 QfNUF0ayZxekfe4TpfmNOFx11Zkr X-Google-Smtp-Source: APXvYqzzpzqddYIb4/GsG0N+SOupy7DZTRvt00T9FYTFSjbpe9qTb83WkEf4S+wahBH9sNKTuz0vMQ== X-Received: by 2002:a17:902:586:: with SMTP id f6mr44427353plf.68.1553811468742; Thu, 28 Mar 2019 15:17:48 -0700 (PDT) Received: from dev-l ([149.28.200.39]) by smtp.gmail.com with ESMTPSA id a8sm238323pfo.144.2019.03.28.15.17.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Mar 2019 15:17:46 -0700 (PDT) Date: Thu, 28 Mar 2019 15:17:45 -0700 From: Denton Liu To: Git Mailing List Cc: Eric Sunshine , Junio C Hamano , Johannes Schindelin , =?iso-8859-1?q?=C6var_Arn?= =?iso-8859-1?q?fj=F6r=F0?= Bjarmason Subject: [PATCH v2] rebase: teach rebase --keep-base Message-ID: <20190328221745.GA3941@dev-l> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A common scenario is if a user is working on a topic branch and they wish to make some changes to intermediate commits or autosquash, they would run something such as git rebase -i --onto master... master in order to preserve the merge base. This prevents unnecessary commit churning. Alternatively, a user wishing to test individual commits in a topic branch without changing anything may run git rebase -x ./test.sh master... master Since rebasing onto the merge base of the branch and the upstream is such a common case, introduce the --keep-base option as a shortcut. This allows us to rewrite the above as git rebase -i --keep-base master and git rebase -x ./test.sh --keep-base master respectively. Add tests to ensure --keep-base works correctly in the normal case and fails when there are multiple merge bases, both in regular and interactive mode. Also, test to make sure conflicting options cause rebase to fail. While we're adding test cases, add a missing set_fake_editor call to 'rebase -i --onto master...side'. While we're documenting the --keep-base option, change an instance of "merge-base" to "merge base", which is the consistent spelling. Helped-by: Eric Sunshine Helped-by: Junio C Hamano Helped-by: Ævar Arnfjörð Bjarmason Signed-off-by: Denton Liu --- Ævar, I have a feeling that we're still miscommunicating and we don't fully understand each other. I'm putting up v2 to hopefully clear things up a little but I welcome more feedback. This patch now depends "[PATCH 1/8] tests (rebase): spell out the `--keep-empty` option" which is the first patch of Johannes's "Do not use abbreviated options in tests" patchset[1]. (Thanks for catching that, Johannes!) Changes since v1: * Squashed old set into one patch * Fixed indentation style and dangling else * Added more documentation after discussion with Ævar [1]: https://public-inbox.org/git/a1b4b74b9167e279dae4cd8c58fb28d8a714a66a.1553537656.git.gitgitgadget@gmail.com/ Documentation/git-rebase.txt | 25 ++++++++++++-- builtin/rebase.c | 32 ++++++++++++++---- t/t3416-rebase-onto-threedots.sh | 57 ++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 9 deletions(-) diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 6363d674b7..27be1f48ff 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -8,8 +8,8 @@ git-rebase - Reapply commits on top of another base tip SYNOPSIS -------- [verse] -'git rebase' [-i | --interactive] [] [--exec ] [--onto ] - [ []] +'git rebase' [-i | --interactive] [] [--exec ] + [--onto | --keep-base] [ []] 'git rebase' [-i | --interactive] [] [--exec ] [--onto ] --root [] 'git rebase' --continue | --skip | --abort | --quit | --edit-todo | --show-current-patch @@ -217,6 +217,19 @@ 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. +--keep-base:: + Set the starting point at which to create the new commits to the + merge base of . Running + 'git rebase --keep-base ' is equivalent to + running 'git rebase --onto ... '. ++ +Although both this option and --fork-point find the merge base between + and , this option uses the merge base as the _starting +point_ on which new commits will be created, whereas --fork-point uses +the merge base to determine the _set of commits_ which will be rebased. ++ +See also INCOMPATIBLE OPTIONS below. + :: Upstream branch to compare against. May be any valid commit, not just an existing branch name. Defaults to the configured @@ -364,6 +377,10 @@ ends up being empty, the will be used as a fallback. + If either or --root is given on the command line, then the default is `--no-fork-point`, otherwise the default is `--fork-point`. ++ +If your branch was based on but was rewound and +your branch contains commits which were dropped, this option can be used +with `--keep-base` in order to drop those commits from your branch. --ignore-whitespace:: --whitespace=