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