Skip to content

Commit 68a163c

Browse files
dschogitster
authored andcommitted
rebase -i: provide reasonable reflog for the rebased branch
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c54b781 commit 68a163c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

git-rebase--interactive.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,14 @@ do_next () {
151151
esac
152152
test -s "$TODO" && return
153153

154-
HEAD=$(git rev-parse HEAD)
155-
HEADNAME=$(cat "$DOTEST"/head-name)
154+
comment_for_reflog finish &&
155+
HEADNAME=$(cat "$DOTEST"/head-name) &&
156+
OLDHEAD=$(cat "$DOTEST"/head) &&
157+
SHORTONTO=$(git rev-parse --short $(cat "$DOTEST"/onto)) &&
158+
NEWHEAD=$(git rev-parse HEAD) &&
159+
message="$GIT_REFLOG_ACTION: $HEADNAME onto $SHORTONTO)" &&
160+
git update-ref -m "$message" $HEADNAME $NEWHEAD $OLDHEAD &&
161+
git symbolic-ref HEAD $HEADNAME &&
156162
rm -rf "$DOTEST" &&
157163
warn "Successfully rebased and updated $HEADNAME."
158164

t/t3404-rebase-interactive.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ test_expect_success 'rebase on top of a non-conflicting commit' '
9999
test $(git rev-parse I) = $(git rev-parse HEAD~2)
100100
'
101101

102+
test_expect_success 'reflog for the branch shows state before rebase' '
103+
test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
104+
'
105+
102106
test_expect_success 'exchange two commits' '
103107
FAKE_LINES="2 1" git rebase -i HEAD~2 &&
104108
test H = $(git cat-file commit HEAD^ | tail -n 1) &&

0 commit comments

Comments
 (0)