1#!/bin/sh 2:${GIT_DIR=.git} 3old=$(git-rev-parse HEAD) 4new= 5force= 6branch= 7while["$#"!="0"];do 8 arg="$1" 9shift 10case"$arg"in 11"-f") 12 force=1 13;; 14*) 15rev=$(git-rev-parse "$arg") 16if[-z"$rev"];then 17echo"unknown flag$arg" 18exit1 19fi 20if["$new"];then 21echo"Multiple revisions?" 22exit1 23fi 24 new="$rev" 25if[-f"$GIT_DIR/refs/heads/$arg"];then 26 branch="$arg" 27fi 28;; 29esac 30 i=$(($i+1)) 31done 32[-z"$new"] && new=$old 33 34if["$force"] 35then 36 git-read-tree --reset$new&& 37 git-checkout-cache -q -f -u -a 38else 39 git-read-tree -m -u$old $new 40fi 41 42# 43# Switch the HEAD pointer to the new branch if it we 44# checked out a branch head, and remove any potential 45# old MERGE_HEAD's (subsequent commits will clearly not 46# be based on them, since we re-set the index) 47# 48if["$?"-eq0];then 49["$branch"] &&ln-sf"refs/heads/$branch""$GIT_DIR/HEAD" 50rm-f"$GIT_DIR/MERGE_HEAD" 51fi