]> git.ipfire.org Git - thirdparty/git.git/blame - git-reset.sh
git-svn: avoid creating some small files
[thirdparty/git.git] / git-reset.sh
CommitLineData
40d8cfe4 1#!/bin/sh
45d197a4 2
806f36d4
FK
3USAGE='[--mixed | --soft | --hard] [<commit-ish>]'
4. git-sh-setup
2f9d685c 5
6ff0b1c5 6tmp=${GIT_DIR}/reset.$$
45d197a4
JH
7trap 'rm -f $tmp-*' 0 1 2 3 15
8
c68998f5 9update=
45d197a4
JH
10reset_type=--mixed
11case "$1" in
12--mixed | --soft | --hard)
13 reset_type="$1"
14 shift
15 ;;
2f9d685c
CS
16-*)
17 usage ;;
45d197a4
JH
18esac
19
2ad77e67
JH
20rev=$(git-rev-parse --verify --default HEAD "$@") || exit
21rev=$(git-rev-parse --verify $rev^0) || exit
45d197a4
JH
22
23# We need to remember the set of paths that _could_ be left
24# behind before a hard reset, so that we can remove them.
25if test "$reset_type" = "--hard"
26then
c68998f5 27 update=-u
45d197a4
JH
28fi
29
30# Soft reset does not touch the index file nor the working tree
31# at all, but requires them in a good order. Other resets reset
32# the index file to the tree object we are switching to.
33if test "$reset_type" = "--soft"
34then
35 if test -f "$GIT_DIR/MERGE_HEAD" ||
36 test "" != "$(git-ls-files --unmerged)"
32173e69 37 then
45d197a4 38 die "Cannot do a soft reset in the middle of a merge."
32173e69 39 fi
45d197a4 40else
c68998f5 41 git-read-tree --reset $update "$rev" || exit
45d197a4
JH
42fi
43
44# Any resets update HEAD to the head being switched to.
45if orig=$(git-rev-parse --verify HEAD 2>/dev/null)
46then
47 echo "$orig" >"$GIT_DIR/ORIG_HEAD"
48else
49 rm -f "$GIT_DIR/ORIG_HEAD"
50fi
67644a4d 51git-update-ref -m "reset $reset_type $@" HEAD "$rev"
45d197a4
JH
52
53case "$reset_type" in
54--hard )
c68998f5 55 ;; # Nothing else to do
45d197a4
JH
56--soft )
57 ;; # Nothing else to do
58--mixed )
59 # Report what has not been updated.
215a7ad1 60 git-update-index --refresh
45d197a4
JH
61 ;;
62esac
63
8389b52b 64rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR"