1#!/bin/sh23USAGE='[--mixed | --soft | --hard] [<commit-ish>]'4. git-sh-setup56update=7reset_type=--mixed8case "$1" in9--mixed | --soft | --hard)10reset_type="$1"11shift12;;13-*)14usage ;;15esac1617case $# in180) rev=HEAD ;;191) rev=$(git-rev-parse --verify "$1") || exit ;;20*) usage ;;21esac22rev=$(git-rev-parse --verify $rev^0) || exit2324# We need to remember the set of paths that _could_ be left25# behind before a hard reset, so that we can remove them.26if test "$reset_type" = "--hard"27then28update=-u29fi3031# Soft reset does not touch the index file nor the working tree32# at all, but requires them in a good order. Other resets reset33# the index file to the tree object we are switching to.34if test "$reset_type" = "--soft"35then36if test -f "$GIT_DIR/MERGE_HEAD" ||37test "" != "$(git-ls-files --unmerged)"38then39die "Cannot do a soft reset in the middle of a merge."40fi41else42git-read-tree --reset $update "$rev" || exit43fi4445# Any resets update HEAD to the head being switched to.46if orig=$(git-rev-parse --verify HEAD 2>/dev/null)47then48echo "$orig" >"$GIT_DIR/ORIG_HEAD"49else50rm -f "$GIT_DIR/ORIG_HEAD"51fi52git-update-ref -m "reset $reset_type $*" HEAD "$rev"53update_ref_status=$?5455case "$reset_type" in56--hard )57;; # Nothing else to do58--soft )59;; # Nothing else to do60--mixed )61# Report what has not been updated.62git-update-index --refresh63;;64esac6566rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" \67"$GIT_DIR/SQUASH_MSG" "$GIT_DIR/MERGE_MSG"6869exit $update_ref_status