🌐 AI搜索 & 代理 主页
blob: fe53fc8065dc82c0054ba9891b28a00b0752bf87 [file] [log] [blame]
Linus Torvalds40d8cfe2005-06-15 01:56:051#!/bin/sh
Junio C Hamano45d197a2005-08-23 00:55:262
freku045@student.liu.se806f36d2005-12-13 22:30:313USAGE='[--mixed | --soft | --hard] [<commit-ish>]'
4. git-sh-setup
c.shoemaker@cox.net2f9d6852005-10-29 04:16:205
Alex Riesen6ff0b1c2006-01-05 11:52:076tmp=${GIT_DIR}/reset.$$
Junio C Hamano45d197a2005-08-23 00:55:267trap 'rm -f $tmp-*' 0 1 2 3 15
8
9reset_type=--mixed
10case "$1" in
11--mixed | --soft | --hard)
12 reset_type="$1"
13 shift
14 ;;
c.shoemaker@cox.net2f9d6852005-10-29 04:16:2015-*)
16 usage ;;
Junio C Hamano45d197a2005-08-23 00:55:2617esac
18
Junio C Hamano2ad77e62005-08-15 22:37:3719rev=$(git-rev-parse --verify --default HEAD "$@") || exit
20rev=$(git-rev-parse --verify $rev^0) || exit
Junio C Hamano45d197a2005-08-23 00:55:2621
22# We need to remember the set of paths that _could_ be left
23# behind before a hard reset, so that we can remove them.
24if test "$reset_type" = "--hard"
25then
26 {
27 git-ls-files --stage -z
28 git-rev-parse --verify HEAD 2>/dev/null &&
29 git-ls-tree -r -z HEAD
30 } | perl -e '
31 use strict;
32 my %seen;
33 $/ = "\0";
34 while (<>) {
35 chomp;
36 my ($info, $path) = split(/\t/, $_);
37 next if ($info =~ / tree /);
38 if (!$seen{$path}) {
39 $seen{$path} = 1;
40 print "$path\0";
41 }
42 }
43 ' >$tmp-exists
44fi
45
46# Soft reset does not touch the index file nor the working tree
47# at all, but requires them in a good order. Other resets reset
48# the index file to the tree object we are switching to.
49if test "$reset_type" = "--soft"
50then
51 if test -f "$GIT_DIR/MERGE_HEAD" ||
52 test "" != "$(git-ls-files --unmerged)"
Junio C Hamano32173e62005-08-07 03:59:4753 then
Junio C Hamano45d197a2005-08-23 00:55:2654 die "Cannot do a soft reset in the middle of a merge."
Junio C Hamano32173e62005-08-07 03:59:4755 fi
Junio C Hamano45d197a2005-08-23 00:55:2656else
57 git-read-tree --reset "$rev" || exit
58fi
59
60# Any resets update HEAD to the head being switched to.
61if orig=$(git-rev-parse --verify HEAD 2>/dev/null)
62then
63 echo "$orig" >"$GIT_DIR/ORIG_HEAD"
64else
65 rm -f "$GIT_DIR/ORIG_HEAD"
66fi
Junio C Hamanobf7960e2005-09-28 01:14:2767git-update-ref HEAD "$rev"
Junio C Hamano45d197a2005-08-23 00:55:2668
69case "$reset_type" in
70--hard )
71 # Hard reset matches the working tree to that of the tree
72 # being switched to.
Junio C Hamano215a7ad2005-09-08 00:26:2373 git-checkout-index -f -u -q -a
Junio C Hamano45d197a2005-08-23 00:55:2674 git-ls-files --cached -z |
75 perl -e '
76 use strict;
77 my (%keep, $fh);
78 $/ = "\0";
79 while (<STDIN>) {
80 chomp;
81 $keep{$_} = 1;
82 }
83 open $fh, "<", $ARGV[0]
84 or die "cannot open $ARGV[0]";
85 while (<$fh>) {
86 chomp;
87 if (! exists $keep{$_}) {
Junio C Hamanoc3bc8952005-09-24 22:02:3588 # it is ok if this fails -- it may already
89 # have been culled by checkout-index.
90 unlink $_;
Junio C Hamano45d197a2005-08-23 00:55:2691 }
92 }
Junio C Hamanoc3bc8952005-09-24 22:02:3593 ' $tmp-exists
Junio C Hamano45d197a2005-08-23 00:55:2694 ;;
95--soft )
96 ;; # Nothing else to do
97--mixed )
98 # Report what has not been updated.
Junio C Hamano215a7ad2005-09-08 00:26:2399 git-update-index --refresh
Junio C Hamano45d197a2005-08-23 00:55:26100 ;;
101esac
102
Junio C Hamano8389b522006-01-29 07:15:24103rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR"