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

[PATCH 2/3] rebase -i: provide reasonable reflog for the rebased branch

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 25, 2007, 17:58 UTC
Message-ID
<Pine.LNX.4.64.0706251857410.4059@racer.site>

If your rebase succeeded, the HEAD's reflog will still show the whole mess, but "<branchname>@{1}" now shows the state _before_ the rebase, so that you can reset (or compare) the original and the rebased revisions more easily.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	Johannes, how about this? ;-)
 git-rebase--interactive.sh    |   10 ++++++++--
 t/t3404-rebase-interactive.sh |    4 ++++
 2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index b95fe86..fb93e13 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -151,8 +151,14 @@ do_next () {
 	esac
 	test -s "$TODO" && return
 
-	HEAD=$(git rev-parse HEAD)
-	HEADNAME=$(cat "$DOTEST"/head-name)
+	comment_for_reflog finish &&
+	HEADNAME=$(cat "$DOTEST"/head-name) &&
+	OLDHEAD=$(cat "$DOTEST"/head) &&
+	SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) &&
+	NEWHEAD=$(git rev-parse HEAD) &&
+	message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
+	git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
+	git symbolic-ref HEAD $HEADNAME &&
 	rm -rf "$DOTEST" &&
 	warn "Successfully rebased and updated $HEADNAME."
 
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 19a3a8e..9f12bb9 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -99,6 +99,10 @@ test_expect_success 'rebase on top of a non-conflicting commit' '
 	test $(git rev-parse I) = $(git rev-parse HEAD~2)
 '
 
+test_expect_success 'reflog for the branch shows state before rebase' '
+	test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
+'
+
 test_expect_success 'exchange two commits' '
 	FAKE_LINES="2 1" git rebase -i HEAD~2 &&
 	test H = $(git cat-file commit HEAD^ | tail -n 1) &&
-- 
1.5.2.2.3172.ge55a1-dirty
Message 1 of 1 in “rebase -i: provide reasonable reflog for the rebased branch”
  1. 2/3 rebase -i: provide reasonable reflog for the rebased branchJohannes Schindelin, Jun 25, 2007

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.