Make "git checkout" know about different branches

Now "git checkout xyzzy" will check out branch "xyzzy" and
switch the HEAD to it.
This commit is contained in:
Linus Torvalds 2005-06-21 11:03:11 -07:00
parent a79944d76c
commit e8b11749f0

View File

@ -1,27 +1,35 @@
#!/bin/sh #!/bin/sh
: ${GIT_DIR=.git} : ${GIT_DIR=.git}
old=$(git-rev-parse HEAD) old=$(git-rev-parse HEAD)
new=$(git-rev-parse --revs-only "$@") new=
new=${new:-$old}
args=($(git-rev-parse --no-revs "$@"))
i=0
force= force=
update= branch=
while [ $i -lt ${#args} ]; do while [ "$#" != "0" ]; do
case "${args[$i]}" in arg="$1"
shift
case "$arg" in
"-f") "-f")
force=1;; force=1
"-u")
update=1;;
"")
;; ;;
*) *)
echo "unknown flag ${args[$i]}" rev=$(git-rev-parse "$arg")
exit 1;; if [ -z "$rev" ]; then
echo "unknown flag $arg"
exit 1
fi
if [ "$new" ]; then
echo "Multiple revisions?"
exit 1
fi
new="$rev"
if [ -f "$GIT_DIR/revs/heads/$arg" ]; then
branch="$arg"
fi
;;
esac esac
i=$(($i+1)) i=$(($i+1))
done done
: ${new=$old}
if [ "$force" ] if [ "$force" ]
then then
@ -29,5 +37,4 @@ then
git-checkout-cache -q -f -u -a git-checkout-cache -q -f -u -a
else else
git-read-tree -m -u $old $new git-read-tree -m -u $old $new
fi && [ "$update" ] && echo $new > "$GIT_DIR/HEAD" fi && [ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD"