{"thread":{"id":"6653","subject":"[PATCH 2/2] Let git-checkout always drop any detached head","startedAt":"2007-02-04T02:50:39Z","lastAt":"2007-02-04T02:58:03Z","messageCount":2,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"33520","messageId":"Pine.LNX.4.64.0702032149200.3021@xanadu.home","threadId":"6653","inReplyTo":null,"subject":"[PATCH 2/2] Let git-checkout always drop any detached head","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-02-04T02:50:39Z","receivedAt":"2007-02-04T02:50:39Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"\nWe used to refuse leaving a detached HEAD when it wasn't matching an\nexisting ref so not to lose any commit that might have been performed\nwhile not on any branch (unless -f was provided).\n\nBut this protection was completely bogus since it was still possible\nto move to HEAD^ while still remaining detached but losing the last\ncommit anyway if there was one.\n\nNow that we have a proper reflog for HEAD it is best to simply remove\nthat bogus (and admitedly annoying) protection and simply display the\nlast HEAD position instead.  If one wants to recover a lost detached\nstate then it can be retrieved from the HEAD reflog.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n git-checkout.sh |   17 ++---------------\n 1 files changed, 2 insertions(+), 15 deletions(-)\n\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex 99b8779..e4cce06 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -164,22 +164,9 @@ If you want to create a new branch from this checkout, you may do so\n (now or later) by using -b with the checkout command again. Example:\n   git checkout -b <new_branch_name>\"\n \tfi\n-elif test -z \"$oldbranch\" && test -n \"$branch\"\n+elif test -z \"$oldbranch\" && && test -z \"$quiet\"\n then\n-\t# Coming back...\n-\tif test -z \"$force\"\n-\tthen\n-\t\tgit show-ref -d -s | grep \"$old\" >/dev/null || {\n-\t\t\techo >&2 \\\n-\"You are not on any branch and switching to branch '$new_name'\n-may lose your changes.  At this point, you can do one of two things:\n- (1) Decide it is Ok and say 'git checkout -f $new_name';\n- (2) Start a new branch from the current commit, by saying\n-     'git checkout -b <branch-name>'.\n-Leaving your HEAD detached; not switching to branch '$new_name'.\"\n-\t\t\texit 1;\n-\t\t}\n-\tfi\n+\techo >&2 \"Previous HEAD position was $old\"\n fi\n \n if [ \"X$old\" = X ]\n-- \n1.5.0.rc2.651.g3924-dirty\n"},{"id":"33521","messageId":"Pine.LNX.4.64.0702032155560.3021@xanadu.home","threadId":"6653","inReplyTo":"Pine.LNX.4.64.0702032149200.3021@xanadu.home","subject":"Re: [PATCH 2/2] Let git-checkout always drop any detached head","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-02-04T02:58:03Z","receivedAt":"2007-02-04T02:58:03Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"\nOK obviously I can't send proper patches today.\n\n\nOn Sat, 3 Feb 2007, Nicolas Pitre wrote:\n\n> diff --git a/git-checkout.sh b/git-checkout.sh\n> index 99b8779..e4cce06 100755\n> --- a/git-checkout.sh\n> +++ b/git-checkout.sh\n> @@ -164,22 +164,9 @@ If you want to create a new branch from this checkout, you may do so\n>  (now or later) by using -b with the checkout command again. Example:\n>    git checkout -b <new_branch_name>\"\n>  \tfi\n> -elif test -z \"$oldbranch\" && test -n \"$branch\"\n> +elif test -z \"$oldbranch\" && && test -z \"$quiet\"\n\nOf course there is one \"&&\" too many.\n\n\nNicolas\n"}]}