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

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 23, 2007, 00:20 UTC
Message-ID
<Pine.LNX.4.64.0711230020080.27959@racer.site>

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>
---
	Yeah, took me a long time to take care of this issue.
 git-checkout.sh |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/git-checkout.sh b/git-checkout.sh
index aa724ac..5dc8ddb 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -266,7 +266,7 @@ if [ "$?" -eq 0 ]; then
 	if test -n "$branch"
 	then
 		old_branch_name=`expr "z$oldbranch" : 'zrefs/heads/\(.*\)'`
-		GIT_DIR="$GIT_DIR" git symbolic-ref -m "checkout: moving from $old_branch_name to $branch" HEAD "refs/heads/$branch"
+		GIT_DIR="$GIT_DIR" git symbolic-ref -m "checkout: moving from ${old_branch_name:-$old} to $branch" HEAD "refs/heads/$branch"
 		if test -n "$quiet"
 		then
 			true	# nothing
@@ -278,7 +278,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:-$old} to $arg" HEAD "$detached" ||
 			die "Cannot detach HEAD"
 		if test -n "$detach_warn"
 		then
-- 
1.5.3.6.1977.g54d30
Message 1 of 1 in “git checkout's reflog: even when detaching the HEAD, say from where”
  1. git checkout's reflog: even when detaching the HEAD, say from whereJohannes Schindelin, Nov 23, 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.