2005-06-15 03:56:05 +02:00
|
|
|
#!/bin/sh
|
2006-12-14 10:19:19 +01:00
|
|
|
#
|
|
|
|
# Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano
|
|
|
|
#
|
|
|
|
USAGE='[--mixed | --soft | --hard] [<commit-ish>] [ [--] <paths>...]'
|
2006-12-14 09:40:15 +01:00
|
|
|
SUBDIRECTORY_OK=Yes
|
2005-12-13 23:30:31 +01:00
|
|
|
. git-sh-setup
|
2006-12-28 08:34:52 +01:00
|
|
|
set_reflog_action "reset $*"
|
2006-12-31 05:32:38 +01:00
|
|
|
require_work_tree
|
2005-10-29 06:16:20 +02:00
|
|
|
|
2006-12-14 10:19:19 +01:00
|
|
|
update= reset_type=--mixed
|
|
|
|
unset rev
|
|
|
|
|
|
|
|
while case $# in 0) break ;; esac
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
--mixed | --soft | --hard)
|
|
|
|
reset_type="$1"
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
rev=$(git-rev-parse --verify "$1") || exit
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
: ${rev=HEAD}
|
|
|
|
rev=$(git-rev-parse --verify $rev^0) || exit
|
|
|
|
|
|
|
|
# Skip -- in "git reset HEAD -- foo" and "git reset -- foo".
|
|
|
|
case "$1" in --) shift ;; esac
|
|
|
|
|
|
|
|
# git reset --mixed tree [--] paths... can be used to
|
|
|
|
# load chosen paths from the tree into the index without
|
|
|
|
# affecting the working tree nor HEAD.
|
|
|
|
if test $# != 0
|
|
|
|
then
|
2007-01-18 12:15:13 +01:00
|
|
|
test "$reset_type" = "--mixed" ||
|
2006-12-14 10:19:19 +01:00
|
|
|
die "Cannot do partial $reset_type reset."
|
2007-01-05 10:38:56 +01:00
|
|
|
|
|
|
|
git-diff-index --cached $rev -- "$@" |
|
|
|
|
sed -e 's/^:\([0-7][0-7]*\) [0-7][0-7]* \([0-9a-f][0-9a-f]*\) [0-9a-f][0-9a-f]* [A-Z] \(.*\)$/\1 \2 \3/' |
|
|
|
|
git update-index --add --remove --index-info || exit
|
2006-12-14 10:19:19 +01:00
|
|
|
git update-index --refresh
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2007-01-12 21:49:05 +01:00
|
|
|
cd_to_toplevel
|
2006-12-14 09:40:15 +01:00
|
|
|
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
if test "$reset_type" = "--hard"
|
|
|
|
then
|
2006-05-14 20:20:37 +02:00
|
|
|
update=-u
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Soft reset does not touch the index file nor the working tree
|
|
|
|
# at all, but requires them in a good order. Other resets reset
|
|
|
|
# the index file to the tree object we are switching to.
|
|
|
|
if test "$reset_type" = "--soft"
|
|
|
|
then
|
|
|
|
if test -f "$GIT_DIR/MERGE_HEAD" ||
|
|
|
|
test "" != "$(git-ls-files --unmerged)"
|
2005-08-07 05:59:47 +02:00
|
|
|
then
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
die "Cannot do a soft reset in the middle of a merge."
|
2005-08-07 05:59:47 +02:00
|
|
|
fi
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
else
|
2007-04-23 19:17:19 +02:00
|
|
|
git-read-tree -v --reset $update "$rev" || exit
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Any resets update HEAD to the head being switched to.
|
|
|
|
if orig=$(git-rev-parse --verify HEAD 2>/dev/null)
|
|
|
|
then
|
|
|
|
echo "$orig" >"$GIT_DIR/ORIG_HEAD"
|
|
|
|
else
|
|
|
|
rm -f "$GIT_DIR/ORIG_HEAD"
|
|
|
|
fi
|
2006-12-28 08:34:52 +01:00
|
|
|
git-update-ref -m "$GIT_REFLOG_ACTION" HEAD "$rev"
|
2006-07-28 07:27:44 +02:00
|
|
|
update_ref_status=$?
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
|
|
|
|
case "$reset_type" in
|
|
|
|
--hard )
|
2006-12-21 15:26:35 +01:00
|
|
|
test $update_ref_status = 0 && {
|
2007-01-16 02:31:29 +01:00
|
|
|
printf "HEAD is now at "
|
2006-12-21 15:26:35 +01:00
|
|
|
GIT_PAGER= git log --max-count=1 --pretty=oneline \
|
|
|
|
--abbrev-commit HEAD
|
|
|
|
}
|
|
|
|
;;
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
--soft )
|
|
|
|
;; # Nothing else to do
|
|
|
|
--mixed )
|
|
|
|
# Report what has not been updated.
|
2005-09-08 02:26:23 +02:00
|
|
|
git-update-index --refresh
|
Introduce "reset type" flag to "git reset"
I have been feeling that the current behaviour of "git reset" is
not quite optimal, but so far could not express exactly what I
felt was wrong with it. This patch clarifies it.
There are at least two situations you may want to "reset" your
working tree.
1. You made a mess in your working tree. You want to switch
back to a known good state and start over. This mess may be
a result of your own editing, a merge that had too many
conflicting changes that you do not feel like to resolve by
hand at this moment, or a botched application of a patch you
received from somewhere.
In this case, you would want to have "git reset HEAD" reset
the index file to the tree read from the HEAD commit and the
files in the working tree to match index (i.e. "git status"
should say "Nothing to commit", without any "unrecorded
changes").
The current behaviour leaves the files in the working tree
intact, which requires you to run "git checkout -f". Also
you need to remember "rm -f" any files that the botched patch
may have left in the working tree if the purpose of this
"reset" is to attempt to apply it again; most likely the
patch would fail if such a file is left behind.
2. You have discovered that commits you made earlier need to be
reorganized. The simplest example is to undo the last
commit, re-edit some files, and redo the commit. Another
simple eample is to undo the last two commits, and commit the
changes in those two commits as a single commit.
In this case, you would want to have "git reset HEAD^" reset
the $GIT_DIR/HEAD to the commit object name of the parent
commit of the current commit (i.e. rewinding one commit),
leave the index file and the files in the working tree in a
state where you can easily make a commit that records a tree
that resembles what you have in the current index file and
the working tree.
The current behaviour is almost OK for this purpose, except
that you need to find which files you need to manually run
"git add" yourself. They are files that are in the original
HEAD commit and not in the commit you are resetting to.
The default without the type flag is to do "--mixed", which is
the current behaviour.
$ git reset [ --hard | --soft | --mixed ] [ <commit-ish> ]
A hard reset would be used for 1 and works in this way:
(1) remember the set of paths that appear in the current
index file (which may even have unmerged entries) and
the current $GIT_DIR/HEAD commit.
(2) "read-tree --reset" the specified <commit-ish> (default
to HEAD), followed by "checkout-cache -f -u -a".
(3) remove any files that appear in (1) but not in
<commit-ish> from the working tree.
(4) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
(5) remove leftover $GIT_DIR/MERGE_HEAD
A soft reset would be used for 2 and works in this way:
(1) Make sure that the index file is merged and we do not
have MERGE_HEAD; otherwise it does not make sense to do
soft reset.
(2) backup $GIT_DIR/HEAD to $GIT_DIR/ORIG_HEAD and update
$GIT_DIR/HEAD with the specified <commit-ish>.
Note that with the current behaviour, "git diff" is the way to
see what could be committed immediately after "git reset". With
the "soft reset" described here you would need to say "git diff
HEAD" to find that out.
I am not sure what mixed reset (the current behaviour) is good
for. If nobody comes up with a good use case it may not be a
bad idea to remove it.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-23 02:55:26 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2006-12-05 04:44:40 +01:00
|
|
|
rm -f "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/rr-cache/MERGE_RR" \
|
|
|
|
"$GIT_DIR/SQUASH_MSG" "$GIT_DIR/MERGE_MSG"
|
2006-07-28 07:27:44 +02:00
|
|
|
|
|
|
|
exit $update_ref_status
|