1#!/bin/sh 2# 3# Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano 4# 5USAGE='[--mixed | --soft | --hard] [<commit-ish>] [ [--] <paths>...]' 6SUBDIRECTORY_OK=Yes 7. git-sh-setup 8set_reflog_action "reset $*" 9 10update= reset_type=--mixed 11unsetrev 12 13while case$#in0)break;;esac 14do 15case"$1"in 16--mixed|--soft|--hard) 17 reset_type="$1" 18;; 19--) 20break 21;; 22-*) 23 usage 24;; 25*) 26rev=$(git-rev-parse --verify "$1")||exit 27shift 28break 29;; 30esac 31shift 32done 33 34:${rev=HEAD} 35rev=$(git-rev-parse --verify $rev^0)||exit 36 37# Skip -- in "git reset HEAD -- foo" and "git reset -- foo". 38case"$1"in--)shift;;esac 39 40# git reset --mixed tree [--] paths... can be used to 41# load chosen paths from the tree into the index without 42# affecting the working tree nor HEAD. 43iftest$#!=0 44then 45test"$reset_type"=="--mixed"|| 46 die "Cannot do partial$reset_typereset." 47 48 git-diff-index --cached$rev--"$@"| 49sed-e's/^:\([0-7][0-7]*\) [0-7][0-7]* \([0-9a-f][0-9a-f]*\) [0-9a-f][0-9a-f]* [A-Z] \(.*\)$/\1 \2 \3/'| 50 git update-index --add --remove --index-info||exit 51 git update-index --refresh 52exit 53fi 54 55TOP=$(git-rev-parse --show-cdup) 56iftest!-z"$TOP" 57then 58cd"$TOP" 59fi 60 61iftest"$reset_type"="--hard" 62then 63 update=-u 64fi 65 66# Soft reset does not touch the index file nor the working tree 67# at all, but requires them in a good order. Other resets reset 68# the index file to the tree object we are switching to. 69iftest"$reset_type"="--soft" 70then 71iftest -f"$GIT_DIR/MERGE_HEAD"|| 72test""!="$(git-ls-files --unmerged)" 73then 74 die "Cannot do a soft reset in the middle of a merge." 75fi 76else 77 git-read-tree --reset$update"$rev"||exit 78fi 79 80# Any resets update HEAD to the head being switched to. 81if orig=$(git-rev-parse --verify HEAD 2>/dev/null) 82then 83echo"$orig">"$GIT_DIR/ORIG_HEAD" 84else 85rm-f"$GIT_DIR/ORIG_HEAD" 86fi 87git-update-ref -m"$GIT_REFLOG_ACTION" HEAD "$rev" 88update_ref_status=$? 89 90case"$reset_type"in 91--hard) 92test$update_ref_status=0&& { 93echo -n"HEAD is now at " 94 GIT_PAGER= git log --max-count=1--pretty=oneline \ 95--abbrev-commit HEAD 96} 97;; 98--soft) 99;;# Nothing else to do 100--mixed) 101# Report what has not been updated. 102 git-update-index --refresh 103;; 104esac 105 106rm-f"$GIT_DIR/MERGE_HEAD""$GIT_DIR/rr-cache/MERGE_RR" \ 107"$GIT_DIR/SQUASH_MSG""$GIT_DIR/MERGE_MSG" 108 109exit$update_ref_status