1#!/bin/sh2: ${GIT_DIR=.git}3old=$(git-rev-parse HEAD)4new=5force=6branch=7while [ "$#" != "0" ]; do8arg="$1"9shift10case "$arg" in11"-f")12force=113;;14*)15rev=$(git-rev-parse --verify --revs-only "$arg")16if [ -z "$rev" ]; then17echo "unknown flag $arg"18exit 119fi20if [ "$new" ]; then21echo "Multiple revisions?"22exit 123fi24new="$rev"25if [ -f "$GIT_DIR/refs/heads/$arg" ]; then26branch="$arg"27fi28;;29esac30i=$(($i+1))31done32[ -z "$new" ] && new=$old3334if [ "$force" ]35then36git-read-tree --reset $new &&37git-checkout-cache -q -f -u -a38else39git-read-tree -m -u $old $new40fi4142#43# Switch the HEAD pointer to the new branch if it we44# checked out a branch head, and remove any potential45# old MERGE_HEAD's (subsequent commits will clearly not46# be based on them, since we re-set the index)47#48if [ "$?" -eq 0 ]; then49[ "$branch" ] && ln -sf "refs/heads/$branch" "$GIT_DIR/HEAD"50rm -f "$GIT_DIR/MERGE_HEAD"51fi