Git development
 help / color / mirror / Atom feed
* Extend "git reset" to take a reset point
@ 2005-08-07  1:01 Linus Torvalds
  2005-08-07  1:42 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Torvalds @ 2005-08-07  1:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List, Sam Ravnborg


This was triggered by a query by Sam Ravnborg, and extends "git reset" to 
reset the index and the .git/HEAD pointer to an arbitrarily named point.

For example

	git reset HEAD^

will just reset the current HEAD to its own parent - leaving the working 
directory untouched, but effectively un-doing the top-most commit. You 
might want to do this if you realize after you committed that you made a 
mistake that you want to fix up: reset your HEAD back to its previous 
state, fix up the working directory and re-do the commit.

If you want to totally un-do the commit (and reset your working directory
to that point too), you'd first use "git reset HEAD^" to reset to the
parent, and then do a "git checkout -f" to reset the working directory
state to that point in time too.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

This is potentially a dangerous command, so maybe we should make it
ask for confirmation first?

On the other hand, it definitely is convenient: I often end up doing this
by hand, and clearly other people have hit the "oops, I want to undo and
then re-do those last five commits, I was just a bit too drunk"

The old "git reset" only reset the index to the current HEAD, which is 
really only useful if you've tried to do a "merge" that failed and that 
you're giving up on. This one is more useful, but also potentially more 
dangerous - doing a

	git reset v0.99.3
	git checkout -f

will basically revert a tree to some old state, and if you didn't save the 
old point, you may not be able to get back to it (git-fsck-cache will help 
you, but..)

Not hugely tested, btw. That strange extra "git-rev-parse" is _meant_ to
make sure that if you reset to a tag, it will always extract the commit ID
from that tag and not reset the HEAD to a tag object.

diff --git a/git-reset-script b/git-reset-script
--- a/git-reset-script
+++ b/git-reset-script
@@ -1,5 +1,7 @@
 #!/bin/sh
 . git-sh-setup-script || die "Not a git archive"
-git-read-tree --reset HEAD
+rev=$(git-rev-parse --revs-only --verify --default HEAD "$@") || exit
+rev=$(git-rev-parse --revs-only --verify $rev^0) || exit
+git-read-tree --reset "$rev" && echo "$rev" > "$GIT_DIR/HEAD"
 git-update-cache --refresh
 rm -f "$GIT_DIR/MERGE_HEAD"

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-07  1:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-07  1:01 Extend "git reset" to take a reset point Linus Torvalds
2005-08-07  1:42 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox