summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 73c838e)
raw | patch | inline | side by side (parent: 73c838e)
author | Junio C Hamano <junkio@cox.net> | |
Mon, 8 Jan 2007 10:42:30 +0000 (02:42 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Mon, 8 Jan 2007 11:02:11 +0000 (03:02 -0800) |
After making commits in the detached HEAD state, if you run "git
checkout" to switch to an existing branch, you will lose your
work. Make sure the switched-to branch is a fast-forward of the
current HEAD, or require -f when switching.
Signed-off-by: Junio C Hamano <junkio@cox.net>
checkout" to switch to an existing branch, you will lose your
work. Make sure the switched-to branch is a fast-forward of the
current HEAD, or require -f when switching.
Signed-off-by: Junio C Hamano <junkio@cox.net>
git-checkout.sh | patch | blob | history |
diff --git a/git-checkout.sh b/git-checkout.sh
index 3250f64ccc683606d420a82b3ec95e2f41bb52b3..69d0c1c43a9f78908f13d3e0e9c34c44587367dd 100755 (executable)
--- a/git-checkout.sh
+++ b/git-checkout.sh
newbranch=
newbranch_log=
merge=
+LF='
+'
while [ "$#" != "0" ]; do
arg="$1"
shift
git checkout -b <new_branch_name> $arg
"
fi
+elif test -z "$oldbranch" && test -n "$branch"
+then
+ # Coming back...
+ if test -z "$force"
+ then
+ mb=$(git merge-base --all $old $new) &&
+ case "$LF$mb$LF" in
+ *"$LF$old$LF"*) : ;;
+ *) false ;;
+ esac || {
+ echo >&2 \
+"You are not on a branch and switching to $new_name branch may lose
+your changes. Use 'git checkout -f $new_name' if you want to."
+ exit 1;
+ }
+ fi
fi
if [ "X$old" = X ]