1#!/bin/sh 2 3USAGE='[--mixed | --soft | --hard] [<commit-ish>]' 4SUBDIRECTORY_OK=Yes 5. git-sh-setup 6 7TOP=$(git-rev-parse --show-cdup) 8iftest!-z"$TOP" 9then 10cd"$TOP" 11fi 12 13update= 14reset_type=--mixed 15case"$1"in 16--mixed|--soft|--hard) 17 reset_type="$1" 18shift 19;; 20-*) 21 usage ;; 22esac 23 24case$#in 250)rev=HEAD ;; 261)rev=$(git-rev-parse --verify "$1")||exit;; 27*) usage ;; 28esac 29rev=$(git-rev-parse --verify $rev^0)||exit 30 31# We need to remember the set of paths that _could_ be left 32# behind before a hard reset, so that we can remove them. 33iftest"$reset_type"="--hard" 34then 35 update=-u 36fi 37 38# Soft reset does not touch the index file nor the working tree 39# at all, but requires them in a good order. Other resets reset 40# the index file to the tree object we are switching to. 41iftest"$reset_type"="--soft" 42then 43iftest -f"$GIT_DIR/MERGE_HEAD"|| 44test""!="$(git-ls-files --unmerged)" 45then 46 die "Cannot do a soft reset in the middle of a merge." 47fi 48else 49 git-read-tree --reset$update"$rev"||exit 50fi 51 52# Any resets update HEAD to the head being switched to. 53if orig=$(git-rev-parse --verify HEAD 2>/dev/null) 54then 55echo"$orig">"$GIT_DIR/ORIG_HEAD" 56else 57rm-f"$GIT_DIR/ORIG_HEAD" 58fi 59git-update-ref -m"reset$reset_type$*" HEAD "$rev" 60update_ref_status=$? 61 62case"$reset_type"in 63--hard) 64;;# Nothing else to do 65--soft) 66;;# Nothing else to do 67--mixed) 68# Report what has not been updated. 69 git-update-index --refresh 70;; 71esac 72 73rm-f"$GIT_DIR/MERGE_HEAD""$GIT_DIR/rr-cache/MERGE_RR" \ 74"$GIT_DIR/SQUASH_MSG""$GIT_DIR/MERGE_MSG" 75 76exit$update_ref_status