1#!/bin/sh2. git-sh-setup-script || die "Not a git archive"34old=$(git-rev-parse HEAD)5new=6force=7branch=8while [ "$#" != "0" ]; do9arg="$1"10shift11case "$arg" in12"-f")13force=114;;15*)16rev=$(git-rev-parse --verify --revs-only "$arg")17if [ -z "$rev" ]; then18echo "unknown flag $arg"19exit 120fi21if [ "$new" ]; then22echo "Multiple revisions?"23exit 124fi25new="$rev"26if [ -f "$GIT_DIR/refs/heads/$arg" ]; then27branch="$arg"28fi29;;30esac31i=$(($i+1))32done33[ -z "$new" ] && new=$old3435if [ "$force" ]36then37git-read-tree --reset $new &&38git-checkout-cache -q -f -u -a39else40git-read-tree -m -u $old $new41fi4243#44# Switch the HEAD pointer to the new branch if it we45# checked out a branch head, and remove any potential46# old MERGE_HEAD's (subsequent commits will clearly not47# be based on them, since we re-set the index)48#49if [ "$?" -eq 0 ]; then50[ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD"51rm -f "$GIT_DIR/MERGE_HEAD"52fi