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

[PATCH] rebase -i: do not fail when there is no commit to cherry-pick

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 10, 2008, 11:42 UTC
Message-ID
<alpine.DEB.1.00.0810101341120.22125@pacific.mpi-cbg.de.mpi-cbg.de>
In-Reply-To
<alpine.DEB.1.00.0810101319150.22125@pacific.mpi-cbg.de.mpi-cbg.de>

In case there is no commit to apply (for example because you rebase to upstream and all your local patches have been applied there), do not fail. The non-interactive rebase already behaves that way.

Do this by introducing a new command, "noop", which is substituted for an empty commit list, so that deleting the commit list can still abort as before.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Fri, 10 Oct 2008, Johannes Schindelin wrote:
	> Maybe we should add a new command "noop" which is automatically 
	> inserted when there is no other command?
	And this implements that.
 git-rebase--interactive.sh    |    3 ++-
 t/t3404-rebase-interactive.sh |   11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 076414a..49a6b5c 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -271,7 +271,7 @@ do_next () {
 		"$DOTEST"/amend || exit
 	read command sha1 rest < "$TODO"
 	case "$command" in
-	'#'*|'')
+	'#'*|''|noop)
 		mark_action_done
 		;;
 	pick|p)
@@ -583,6 +583,7 @@ first and then run 'git rebase --continue' again."
 			--abbrev=7 --reverse --left-right --cherry-pick \
 			$UPSTREAM...$HEAD | \
 			sed -n "s/^>/pick /p" > "$TODO"
+		test -s "$TODO" || echo noop >> "$TODO"
 		cat >> "$TODO" << EOF
 
 # Rebase $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index e0ded19..7d10a27 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -419,4 +419,15 @@ test_expect_success 'rebase with a file named HEAD in worktree' '
 
 '
 
+test_expect_success 'do "noop" when there is nothing to cherry-pick' '
+
+	git checkout -b branch4 HEAD &&
+	GIT_EDITOR=: git commit --amend \
+		--author="Somebody else <somebody@else.com>" 
+	test $(git rev-parse branch3) != $(git rev-parse branch4) &&
+	git rebase -i branch3 &&
+	test $(git rev-parse branch3) = $(git rev-parse branch4)
+
+'
+
 test_done
-- 
1.6.0.2.713.g3dcb0
Previous: Johannes Schindelin
Message 4 of 4 in “Different behaviour of rebase -i”
  1. Leonardo Sobral CunhaOct 9, 2008
  2. Caio Marcelo de Oliveira FilhoOct 9, 2008
  3. Johannes SchindelinOct 10, 2008
  4. rebase -i: do not fail when there is no commit to cherry-pickJohannes Schindelin, Oct 10, 2008

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.