From 49ed2bc4660c7cd0592cf21cc514080574d06320 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 4 Dec 2006 19:44:40 -0800 Subject: git-reset to remove "$GIT_DIR/MERGE_MSG" An earlier commit a9cb3c6e changed git-commit to use the contents of MERGE_MSG even when we do not have MERGE_HEAD (the rationale is in its log message). However, the change tricks the following sequence to include a merge message in a completely unrelated commit: $ git pull somewhere : oops, the conflicts are too much. forget it. $ git reset --hard : work work work $ git commit To fix this confusion, this patch makes "git reset" to remove the leftover MERGE_MSG that was prepared when the user abandoned the merge. Signed-off-by: Junio C Hamano Acked-by: Luben Tuikov Date: Thu, 14 Dec 2006 00:40:15 -0800 Subject: git-reset: make it work from within a subdirectory. If you typically sit in, say "src/", it's annoying to have to change directory to do a reset. This may need to be reworked when we add "git reset -- paths..." to encapsulate the "ls-tree $tree | update-index --index-info" pattern. Signed-off-by: Junio C Hamano --- git-reset.sh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'git-reset.sh') diff --git a/git-reset.sh b/git-reset.sh index c0feb4435d..03d2c3b937 100755 --- a/git-reset.sh +++ b/git-reset.sh @@ -1,8 +1,15 @@ #!/bin/sh USAGE='[--mixed | --soft | --hard] []' +SUBDIRECTORY_OK=Yes . git-sh-setup +TOP=$(git-rev-parse --show-cdup) +if test ! -z "$TOP" +then + cd "$TOP" +fi + update= reset_type=--mixed case "$1" in -- cgit v1.3 From 2ce633b928f78224a37308f45810e76fefe8df56 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 14 Dec 2006 01:19:19 -0800 Subject: git-reset [--mixed] [--] ... 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 -- ...". 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 --- git-reset.sh | 69 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 22 deletions(-) (limited to 'git-reset.sh') diff --git a/git-reset.sh b/git-reset.sh index 03d2c3b937..8d95e3748d 100755 --- a/git-reset.sh +++ b/git-reset.sh @@ -1,35 +1,60 @@ #!/bin/sh - -USAGE='[--mixed | --soft | --hard] []' +# +# Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano +# +USAGE='[--mixed | --soft | --hard] [] [ [--] ...]' SUBDIRECTORY_OK=Yes . git-sh-setup +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 + test "$reset_type" == "--mixed" || + die "Cannot do partial $reset_type reset." + git ls-tree -r --full-name $rev -- "$@" | + git update-index --add --index-info || exit + git update-index --refresh + exit +fi + TOP=$(git-rev-parse --show-cdup) if test ! -z "$TOP" then cd "$TOP" fi -update= -reset_type=--mixed -case "$1" in ---mixed | --soft | --hard) - reset_type="$1" - shift - ;; --*) - usage ;; -esac - -case $# in -0) rev=HEAD ;; -1) rev=$(git-rev-parse --verify "$1") || exit ;; -*) usage ;; -esac -rev=$(git-rev-parse --verify $rev^0) || exit - -# We need to remember the set of paths that _could_ be left -# behind before a hard reset, so that we can remove them. if test "$reset_type" = "--hard" then update=-u -- cgit v1.3 From 95f2fb7d9f84779bf036bb748e245c91bc572840 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 21 Dec 2006 15:26:35 +0100 Subject: git-reset --hard: tell the user what the HEAD was reset to Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-reset.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'git-reset.sh') diff --git a/git-reset.sh b/git-reset.sh index 8d95e3748d..2379db082f 100755 --- a/git-reset.sh +++ b/git-reset.sh @@ -86,7 +86,12 @@ update_ref_status=$? case "$reset_type" in --hard ) - ;; # Nothing else to do + test $update_ref_status = 0 && { + echo -n "HEAD is now at " + GIT_PAGER= git log --max-count=1 --pretty=oneline \ + --abbrev-commit HEAD + } + ;; --soft ) ;; # Nothing else to do --mixed ) -- cgit v1.3