# [PATCH] git checkout's reflog: even when detaching the HEAD, say from where

2 messages from 2007-08-07 to 2007-08-07. Participants: Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/9414

## Johannes Schindelin, 2007-08-07 01:42

Subject: [PATCH] git checkout's reflog: even when detaching the HEAD, say from where
Message-ID: <Pine.LNX.4.64.0708070242140.14781@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0708070242140.14781%40racer.site

```

When checking out another ref, the reflogs already record from which
branch you switched.  Do that also when switching to a detached HEAD.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-checkout.sh |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/git-checkout.sh b/git-checkout.sh
index 17f4392..f427718 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -272,7 +272,8 @@ if [ "$?" -eq 0 ]; then
 		fi
 	elif test -n "$detached"
 	then
-		git update-ref --no-deref -m "checkout: moving to $arg" HEAD "$detached" ||
+		old_branch_name=`expr "z$oldbranch" : 'zrefs/heads/\(.*\)'`
+		git update-ref --no-deref -m "checkout: moving from $old_branch_name to $arg" HEAD "$detached" ||
 			die "Cannot detach HEAD"
 		if test -n "$detach_warn"
 		then
-- 
1.5.3.rc4.17.gb980

```

## Junio C Hamano, 2007-08-07 03:56

Subject: Re: [PATCH] git checkout's reflog: even when detaching the HEAD, say from where
Message-ID: <7v8x8o9euy.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v8x8o9euy.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.64.0708070242140.14781@racer.site>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> @@ -272,7 +272,8 @@ if [ "$?" -eq 0 ]; then
>  		fi
>  	elif test -n "$detached"
>  	then
> -		git update-ref --no-deref -m "checkout: moving to $arg" HEAD "$detached" ||
> +		old_branch_name=`expr "z$oldbranch" : 'zrefs/heads/\(.*\)'`
> +		git update-ref --no-deref -m "checkout: moving from $old_branch_name to $arg" HEAD "$detached" ||

Can't old_branch_name be empty here if you are already detached?

>  			die "Cannot detach HEAD"
>  		if test -n "$detach_warn"
>  		then
> -- 
> 1.5.3.rc4.17.gb980

```
