git-checkout: rewording comments regarding detached HEAD.
We used to say "you are not on a branch" before the initial commit. This is incorrect -- the user is on a branch yet to be born, but its name has been already determined. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 8, 2007 at 02:08 UTC
73c838e4c9437a0c41082c32a3a832aa385460a9
1 file changed
+12
-9
git-checkout.sh
+12
-9
@@ -140,22 +140,25 @@ fi
140
141
[ -z "$new" ] && new=$old && new_name="$old_name"
142
143
-# If we don't have an old branch that we're switching to,
143
+# If we don't have an existing branch that we're switching to,
144
# and we don't have a new branch name for the target we
145
-# are switching to, then we'd better just be checking out
146
-# what we already had
145
+# are switching to, then we are detaching our HEAD from any
146
+# branch. However, if "git checkout HEAD" detaches the HEAD
147
+# from the current branch, even though that may be logically
148
+# correct, it feels somewhat funny. More importantly, we do not
149
+# want "git checkout" nor "git checkout -f" to detach HEAD.
150
151
if test -z "$branch$newbranch" && test "$new" != "$old"
152
then
150
- # NEEDSWORK: we would want to have this command here
151
- # that allows us to detach the HEAD atomically.
152
- # git update-ref --detach HEAD "$new"
153
+ # NEEDSWORK: we would want to have a command here
154
+ # that allows us to detach the HEAD atomically. Perhaps
155
+ # something like "git update-ref --detach HEAD $new"
156
echo "$new" >"$GIT_DIR/HEAD.new" &&
157
mv "$GIT_DIR/HEAD.new" "$GIT_DIR/HEAD" || die "Cannot detach HEAD"
158
159
if test -n "$oldbranch"
160
then
158
- echo >&2 "WARNING: you are not on ANY branch anymore.
161
+ echo >&2 "warning: you are not on ANY branch anymore.
162
If you meant to create a new branch from the commit, you need -b to
163
associate a new branch with the wanted checkout. Example:
164
git checkout -b <new_branch_name> $arg
@@ -165,8 +168,8 @@ fi
168
169
if [ "X$old" = X ]
170
then
168
- echo "warning: You do not appear to currently be on a branch." >&2
169
- echo "warning: Forcing checkout of $new_name." >&2
171
+ echo >&2 "warning: You appear to be on a branch yet to be born."
172
+ echo >&2 "warning: Forcing checkout of $new_name."
173
force=1
174
fi
175