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

Let git-checkout always drop any detached head

We used to refuse leaving a detached HEAD when it wasn't matching an existing ref so not to lose any commit that might have been performed while not on any branch (unless -f was provided). But this protection was completely bogus since it was still possible to move to HEAD^ while still remaining detached but losing the last commit anyway if there was one. Now that we have a proper reflog for HEAD it is best to simply remove that bogus (and admitedly annoying) protection and simply display the last HEAD position instead. If one wants to recover a lost detached state then it can be retrieved from the HEAD reflog. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Nicolas Pitre committed Feb 3, 2007 at 21:50 UTC dc9195ac7830bdf08ee847ef6a385c0b8f673d69
1 file changed +2 -15
git-checkout.sh
+2 -15
@@ -164,22 +164,9 @@ If you want to create a new branch from this checkout, you may do so
164 (now or later) by using -b with the checkout command again. Example:
165 git checkout -b <new_branch_name>"
166 fi
167 -elif test -z "$oldbranch" && test -n "$branch"
167 +elif test -z "$oldbranch" && test -z "$quiet"
168 then
169 - # Coming back...
170 - if test -z "$force"
171 - then
172 - git show-ref -d -s | grep "$old" >/dev/null || {
173 - echo >&2 \
174 -"You are not on any branch and switching to branch '$new_name'
175 -may lose your changes. At this point, you can do one of two things:
176 - (1) Decide it is Ok and say 'git checkout -f $new_name';
177 - (2) Start a new branch from the current commit, by saying
178 - 'git checkout -b <branch-name>'.
179 -Leaving your HEAD detached; not switching to branch '$new_name'."
180 - exit 1;
181 - }
182 - fi
169 + echo >&2 "Previous HEAD position was $old"
170 fi
171
172 if [ "X$old" = X ]