[prev in list] [next in list] [prev in thread] [next in thread] 

List:       git
Subject:    Re: Instructions concerning detached head lead to lost local changes
From:       Linus Torvalds <torvalds () linux-foundation ! org>
Date:       2007-02-01 23:49:57
Message-ID: Pine.LNX.4.64.0702011536570.15057 () woody ! linux-foundation ! org
[Download RAW message or body]



On Thu, 1 Feb 2007, Carl Worth wrote:
> 
> But I found that after "git checkout -f master" I lost the dirty
> changes I had made. And I don't see anything in the message above
> telling me a better way to get from the state I was in to the state I
> wanted.

Yeah, I think "-f" was a mistake. 

There was already real meaning for "-f": force update of all the files, 
regardless of whether they are dirty or unmerged or anything else.

And that meaning is totally independent of the new meaning of -f, which 
says "drop the old detached head". Sometimes you might want to use them 
together, but they shouldn't really be tied together.

Maybe something like this, which adds "--drop" as the flag to say "ok to 
drop the old detached head"? I'm not married to that name, it's meant more 
as an RFC than as anything to be applied as-is.

NOTE! This makes "-f" _imply_ "--drop" too, since it does make sense that 
if somebody just wants to force it, he can - regardless of any dirty 
state, regardless of the current state of the HEAD.

But using just "git checkout --drop new-head" will have the old "dirty 
state follows along with branch changes" semantics.

		Linus

PS. I don't think "--drop" really makes much sense as a name. Especially 
when written out like that, it sounds like we're dropping the *new* 
branch, not the old one. Maybe something like "--no-check" instead?

---
diff --git a/git-checkout.sh b/git-checkout.sh
index deb4795..8e852df 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -11,6 +11,7 @@ oldbranch=$(git-symbolic-ref $old_name 2>/dev/null)
 new=
 new_name=
 force=
+drop=
 branch=
 newbranch=
 newbranch_log=
@@ -36,10 +37,14 @@ while [ "$#" != "0" ]; do
 		;;
 	"-f")
 		force=1
+		drop=1
 		;;
 	-m)
 		merge=1
 		;;
+	--drop)
+		drop=1
+		;;
 	--)
 		break
 		;;
@@ -163,7 +168,7 @@ If you want to create a new branch from this checkout, you may do so
 elif test -z "$oldbranch" && test -n "$branch"
 then
 	# Coming back...
-	if test -z "$force"
+	if test -z "$drop"
 	then
 		git show-ref -d -s | grep "$old" >/dev/null || {
 			echo >&2 \
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic