From c847f537125ceab3425205721fdaaa834e6d8a83 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 1 Jan 2007 23:31:08 -0800 Subject: Detached HEAD (experimental) This allows "git checkout v1.4.3" to dissociate the HEAD of repository from any branch. After this point, "git branch" starts reporting that you are not on any branch. You can go back to an existing branch by saying "git checkout master", for example. This is still experimental. While I think it makes sense to allow commits on top of detached HEAD, it is rather dangerous unless you are careful in the current form. Next "git checkout master" will obviously lose what you have done, so we might want to require "git checkout -f" out of a detached HEAD if we find that the HEAD commit is not an ancestor of any other branches. There is no such safety valve implemented right now. On the other hand, the reason the user did not start the ad-hoc work on a new branch with "git checkout -b" was probably because the work was of a throw-away nature, so the convenience of not having that safety valve might be even better. The user, after accumulating some commits on top of a detached HEAD, can always create a new branch with "git checkout -b" not to lose useful work done while the HEAD was detached. We'll see. Signed-off-by: Junio C Hamano --- git-checkout.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'git-checkout.sh') diff --git a/git-checkout.sh b/git-checkout.sh index 92ec069a3a..8e11ca4bc8 100755 --- a/git-checkout.sh +++ b/git-checkout.sh @@ -144,13 +144,19 @@ fi # are switching to, then we'd better just be checking out # what we already had -[ -z "$branch$newbranch" ] && - [ "$new" != "$old" ] && - die "git checkout: provided reference cannot be checked out directly - - You need -b to associate a new branch with the wanted checkout. Example: +if test -z "$branch$newbranch" && test "$new" != "$old" +then + # NEEDSWORK: we would want to have this command here + # that allows us to detach the HEAD atomically. + # git update-ref --detach HEAD "$new" + rm -f "$GIT_DIR/HEAD" + echo "$new" >"$GIT_DIR/HEAD" + echo >&2 "WARNING: you are not on ANY branch anymore. +If you meant to create a new branch from the commit, you need -b to +associate a new branch with the wanted checkout. Example: git checkout -b $arg " +fi if [ "X$old" = X ] then -- cgit v1.2.3