3 # Reset the state of the working tree
4 # Copyright (c) Petr Baudis, 2005
6 # Reverts the working tree to a consistent state before any changes to it
7 # (including merges etc.) were done. This command will rebuild the state
8 # of the tree according to the latest commit on your current branch, so if
9 # your working tree got into basically any inconsistent state, this will
12 # Basically, this is the opposite of `cg-commit` in some sense.
14 # This command is complementary to `cg-restore`, which only brings
15 # individual files in sync with their state at the time of the
20 # --adds-removes:: Only reset info about added and removed files
21 # Reset ONLY the so-called "index" file. This effectively means that
22 # any adds and removes you did will be unrecorded (but if you removed
23 # the file physically as well, that will not be undone - run
24 # 'cg-restore' to restore it physically afterwards).
28 USAGE
="cg-reset [--adds-removes]"
31 .
"${COGITO_LIB}"cg-Xlib ||
exit 1
36 if optparse
--adds-removes; then
43 [ "${ARGS[0]}" ] && die
"this command takes no parameters; use cg-restore to restore individual files"
46 if [ "$indexonly" ]; then
47 ( git-read-tree
--reset HEAD
) && git-update-index
--refresh
52 if ! [ -s "$_git/HEAD" ]; then
54 # XXX: git-symbolic-ref is a weenie and won't do the job at this point.
55 echo "ref: refs/heads/$_git_head" >"$_git/HEAD"
59 if [ -s "$_git/head-name" ]; then
60 seekpt
="$(get_ref "refs
/heads
/cg-seek-point
")"
61 echo "Unseeking: $(get_ref "$
(git-symbolic-ref HEAD
)") -> $(get_ref "refs
/heads
/$_git_head") ($_git_head)"
62 if exists_ref
"refs/heads/$_git_head"; then
63 git-symbolic-ref HEAD
"refs/heads/$_git_head"
64 git-update-ref
-d "refs/heads/cg-seek-point" "$seekpt"
67 echo "ERROR: Unknown branch $_git_head! Cancelling unseek." >&2
72 rm -rf "$_git/cg-merge-state"
73 # Moved to cg-merge-state as of 2006-11-17
74 rm -f "$_git/merging" "$_git/merging-sym" "$_git/merge-base" "$_git/commit-ignore" "$_git/squashing"
75 git-read-tree
--reset HEAD
77 git-checkout-index
-u -f -a