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

[PATCH v2] git-rebase: Teach rebase "-" shorthand.

From
Brian Gesiak <modocache@gmail.com>
Date
Mar 19, 2014, 11:02 UTC
Message-ID
<1395226935-53044-1-git-send-email-modocache@gmail.com>
In-Reply-To
<xmqq61nb8fap.fsf@gitster.dls.corp.google.com>

Teach rebase the same shorthand as checkout and merge; that is, that "-" means "the branch we were previously on".

Reported-by: Tim Chase <git@tim.thechases.com>
Signed-off-by: Brian Gesiak <modocache@gmail.com>
---
 git-rebase.sh     |  4 ++++
 t/t3400-rebase.sh | 11 +++++++++++
 2 files changed, 15 insertions(+)
diff --git a/git-rebase.sh b/git-rebase.sh
index 5f6732b..2c75e9f 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -453,6 +453,10 @@ then
 		test "$fork_point" = auto && fork_point=t
 		;;
 	*)	upstream_name="$1"
+		if test "$upstream_name" = "-"
+		then
+			upstream_name="@{-1}"
+		fi
 		shift
 		;;
 	esac
diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
index 6d94b1f..6176754 100755
--- a/t/t3400-rebase.sh
+++ b/t/t3400-rebase.sh
@@ -88,6 +88,17 @@ test_expect_success 'rebase from ambiguous branch name' '
 	git rebase master
 '
 
+test_expect_success 'rebase using shorthand' '
+	git checkout master &&
+	git checkout -b shorthand HEAD^ &&
+	git rebase - 1>shorthand.stdout &&
+	git checkout master &&
+	git branch -D shorthand &&
+	git checkout -b shorthand HEAD^ &&
+	git rebase @{-1} 1>without_shorthand.stdout &&
+	test_i18ncmp without_shorthand.stdout shorthand.stdout
+'
+
 test_expect_success 'rebase a single mode change' '
 	git checkout master &&
 	git branch -D topic &&
-- 
1.8.5.2 (Apple Git-48)
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 12 in “git-rebase: Teach rebase "-" shorthand.”
  1. git-rebase: Teach rebase "-" shorthand.Brian Gesiak, Mar 18, 2014
  2. Torsten BögershausenMar 18, 2014
  3. Junio C HamanoMar 18, 2014
  4. git-rebase: Teach rebase "-" shorthand.Brian Gesiak, Mar 19, 2014
  5. Junio C HamanoMar 19, 2014
  6. John KeepingMar 19, 2014
  7. Brian GesiakMar 19, 2014
  8. Junio C HamanoMar 19, 2014
  9. John KeepingMar 19, 2014
  10. Junio C HamanoMar 19, 2014
  11. John KeepingMar 19, 2014
  12. Junio C HamanoMar 19, 2014

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.