@matheusbsbs / matheus-bagliano / commits / c67bbc55f0
Fork 0

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>

Johannes Schindelin committed Nov 23, 2007 at 00:20 UTC c67bbc55f0310de79647457b1fa2a5d3b1746488
1 file changed +3 -2
git-checkout.sh
+3 -2
@@ -266,7 +266,7 @@ if [ "$?" -eq 0 ]; then
266 if test -n "$branch"
267 then
268 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"
270 if test -n "$quiet"
271 then
272 true # nothing
@@ -278,7 +278,8 @@ if [ "$?" -eq 0 ]; then
278 fi
279 elif test -n "$detached"
280 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" ||
283 die "Cannot detach HEAD"
284 if test -n "$detach_warn"
285 then