git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] rebase -i: avoid --cherry-pick when rebasing to a direct ancestor

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 19, 2010, 23:30 UTC
Message-ID
<d1a75633daa062b25527dfb0675673480974c940.1266620423.git.trast@student.ethz.ch>
In-Reply-To
<dfb660301002191324i7aeca7f5x990501bbca1475a9@mail.gmail.com>
Ordinary 'rebase -i' reads the commits to rebase with (roughly)
  git rev-list --left-right --cherry-pick $upstream...

which gives it the feature of skipping commits that are already present in $upstream. However, in the common use-case of rewriting a few commits up to an ancestor, as in 'git rebase -i HEAD~3', the --cherry-pick is useless since there are no commits to compare to.

Add a check if $upstream is a direct ancestor of HEAD, and leave away the --cherry-pick if so. Since the --cherry-pick is already in $MERGES_OPTION, we need to decide this before setting the latter.

For simplicity we skip --root mode. In theory we could do the same optimization, but using --root --onto <ancestor> is probably even more rare than having performance issues with --cherry-pick.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---

The --cherry-pick mechanism itself could get a similar optimization, but I don't know that code.

 git-rebase--interactive.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 1fda620..10b0ed8 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -870,7 +870,12 @@ first and then run 'git rebase --continue' again."
 			MERGES_OPTION=
 			first_after_upstream="$(git rev-list --reverse --first-parent $UPSTREAM..$HEAD | head -n 1)"
 		else
-			MERGES_OPTION="--no-merges --cherry-pick"
+			if test -z "$REBASE_ROOT" &&
+				test $(git merge-base $UPSTREAM $HEAD) = $UPSTREAM; then
+				MERGES_OPTION="--no-merges"
+			else
+				MERGES_OPTION="--no-merges --cherry-pick"
+			fi
 		fi
 
 		SHORTHEAD=$(git rev-parse --short $HEAD)
-- 
1.7.0.139.gd1a75
Previous: Laine Walker-AvinaNext: Thomas Rast
Message 2 of 8 in “Git has bad performance when traversing change-sets with large PPM files”
  1. Laine Walker-AvinaFeb 19, 2010
  2. rebase -i: avoid --cherry-pick when rebasing to a direct ancestorThomas Rast, Feb 19, 2010
  3. Thomas RastFeb 20, 2010
  4. Jeff KingFeb 20, 2010
  5. cherry_pick_list: quit early if one side is emptyThomas Rast, Feb 20, 2010
  6. Jeff KingFeb 21, 2010
  7. Thomas RastFeb 20, 2010
  8. Jeff KingFeb 21, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.