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