@matheusbsbs / matheus-bagliano / commits / 2ce633b928
Fork 0

git-reset [--mixed] <tree> [--] <paths>...

Sometimes it is asked on the list how to revert selected path in the index from a tree, most often HEAD, without affecting the files in the working tree. A similar operation that also affects the working tree files has been available in the form of "git checkout <tree> -- <paths>...". By definition --soft would never affect either the index nor the working tree files, and --hard is the way to make the working tree files as close to pristine, so this new option is available only for the default --mixed case. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Dec 14, 2006 at 01:19 UTC 2ce633b928f78224a37308f45810e76fefe8df56
1 file changed +47 -22
git-reset.sh
+47 -22
@@ -1,35 +1,60 @@
1 #!/bin/sh
2 -
3 -USAGE='[--mixed | --soft | --hard] [<commit-ish>]'
2 +#
3 +# Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
4 +#
5 +USAGE='[--mixed | --soft | --hard] [<commit-ish>] [ [--] <paths>...]'
6 SUBDIRECTORY_OK=Yes
7 . git-sh-setup
8
9 +update= reset_type=--mixed
10 +unset rev
11 +
12 +while case $# in 0) break ;; esac
13 +do
14 + case "$1" in
15 + --mixed | --soft | --hard)
16 + reset_type="$1"
17 + ;;
18 + --)
19 + break
20 + ;;
21 + -*)
22 + usage
23 + ;;
24 + *)
25 + rev=$(git-rev-parse --verify "$1") || exit
26 + shift
27 + break
28 + ;;
29 + esac
30 + shift
31 +done
32 +
33 +: ${rev=HEAD}
34 +rev=$(git-rev-parse --verify $rev^0) || exit
35 +
36 +# Skip -- in "git reset HEAD -- foo" and "git reset -- foo".
37 +case "$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.
42 +if test $# != 0
43 +then
44 + test "$reset_type" == "--mixed" ||
45 + die "Cannot do partial $reset_type reset."
46 + git ls-tree -r --full-name $rev -- "$@" |
47 + git update-index --add --index-info || exit
48 + git update-index --refresh
49 + exit
50 +fi
51 +
52 TOP=$(git-rev-parse --show-cdup)
53 if test ! -z "$TOP"
54 then
55 cd "$TOP"
56 fi
57
13 -update=
14 -reset_type=--mixed
15 -case "$1" in
16 ---mixed | --soft | --hard)
17 - reset_type="$1"
18 - shift
19 - ;;
20 --*)
21 - usage ;;
22 -esac
23 -
24 -case $# in
25 -0) rev=HEAD ;;
26 -1) rev=$(git-rev-parse --verify "$1") || exit ;;
27 -*) usage ;;
28 -esac
29 -rev=$(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.
58 if test "$reset_type" = "--hard"
59 then
60 update=-u