{"thread":{"id":"10986","subject":"[PATCH] git checkout's reflog: even when detaching the HEAD, say from where","startedAt":"2007-11-23T00:20:35Z","lastAt":"2007-11-23T00:20:35Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60722","messageId":"Pine.LNX.4.64.0711230020080.27959@racer.site","threadId":"10986","inReplyTo":null,"subject":"[PATCH] git checkout's reflog: even when detaching the HEAD, say from where","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-11-23T00:20:35Z","receivedAt":"2007-11-23T00:20:35Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWhen checking out another ref, the reflogs already record from which\nbranch you switched.  Do that also when switching to a detached HEAD.\n\nWhile at it, record also when coming _from_ a detached HEAD.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tYeah, took me a long time to take care of this issue.\n\n git-checkout.sh |    5 +++--\n 1 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex aa724ac..5dc8ddb 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -266,7 +266,7 @@ if [ \"$?\" -eq 0 ]; then\n \tif test -n \"$branch\"\n \tthen\n \t\told_branch_name=`expr \"z$oldbranch\" : 'zrefs/heads/\\(.*\\)'`\n-\t\tGIT_DIR=\"$GIT_DIR\" git symbolic-ref -m \"checkout: moving from $old_branch_name to $branch\" HEAD \"refs/heads/$branch\"\n+\t\tGIT_DIR=\"$GIT_DIR\" git symbolic-ref -m \"checkout: moving from ${old_branch_name:-$old} to $branch\" HEAD \"refs/heads/$branch\"\n \t\tif test -n \"$quiet\"\n \t\tthen\n \t\t\ttrue\t# nothing\n@@ -278,7 +278,8 @@ if [ \"$?\" -eq 0 ]; then\n \t\tfi\n \telif test -n \"$detached\"\n \tthen\n-\t\tgit update-ref --no-deref -m \"checkout: moving to $arg\" HEAD \"$detached\" ||\n+\t\told_branch_name=`expr \"z$oldbranch\" : 'zrefs/heads/\\(.*\\)'`\n+\t\tgit update-ref --no-deref -m \"checkout: moving from ${old_branch_name:-$old} to $arg\" HEAD \"$detached\" ||\n \t\t\tdie \"Cannot detach HEAD\"\n \t\tif test -n \"$detach_warn\"\n \t\tthen\n-- \n1.5.3.6.1977.g54d30\n"}]}