Skip to content

Commit c67bbc5

Browse files
dschogitster
authored andcommitted
git checkout's reflog: even when detaching the HEAD, say from where
When checking out another ref, the reflogs already record from which branch you switched. Do that also when switching to a detached HEAD. While at it, record also when coming _from_ a detached HEAD. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9e42d6a commit c67bbc5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

git-checkout.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ if [ "$?" -eq 0 ]; then
266266
if test -n "$branch"
267267
then
268268
old_branch_name=`expr "z$oldbranch" : 'zrefs/heads/\(.*\)'`
269-
GIT_DIR="$GIT_DIR" git symbolic-ref -m "checkout: moving from $old_branch_name to $branch" HEAD "refs/heads/$branch"
269+
GIT_DIR="$GIT_DIR" git symbolic-ref -m "checkout: moving from ${old_branch_name:-$old} to $branch" HEAD "refs/heads/$branch"
270270
if test -n "$quiet"
271271
then
272272
true # nothing
@@ -278,7 +278,8 @@ if [ "$?" -eq 0 ]; then
278278
fi
279279
elif test -n "$detached"
280280
then
281-
git update-ref --no-deref -m "checkout: moving to $arg" HEAD "$detached" ||
281+
old_branch_name=`expr "z$oldbranch" : 'zrefs/heads/\(.*\)'`
282+
git update-ref --no-deref -m "checkout: moving from ${old_branch_name:-$old} to $arg" HEAD "$detached" ||
282283
die "Cannot detach HEAD"
283284
if test -n "$detach_warn"
284285
then

0 commit comments

Comments
 (0)