summaryrefslogtreecommitdiff
path: root/git-stash.sh
diff options
context:
space:
mode:
authorAbhijit Menon-Sen <ams@toroid.org>2008-07-03 11:46:05 +0530
committerJunio C Hamano <gitster@pobox.com>2008-07-05 00:39:37 -0700
commit656b50345239293929ad8c639c5f1941c6b867ad (patch)
tree2ad9d58711dd3dc3bd5def98ccfa017f949ed102 /git-stash.sh
parent6991357513bf8bfbb71a4675e271b386cc273476 (diff)
downloadgit-656b50345239293929ad8c639c5f1941c6b867ad.tar.gz
Implement "git stash branch <newbranch> <stash>"
Restores the stashed state on a new branch rooted at the commit on which the stash was originally created, so that conflicts caused by subsequent changes on the original branch can be dealt with. (Thanks to Junio for this nice idea.) Signed-off-by: Abhijit Menon-Sen <ams@toroid.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-stash.sh')
-rwxr-xr-xgit-stash.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/git-stash.sh b/git-stash.sh
index 4938ade589..889445c4fc 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -218,6 +218,23 @@ drop_stash () {
git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash
}
+apply_to_branch () {
+ have_stash || die 'Nothing to apply'
+
+ test -n "$1" || die 'No branch name specified'
+ branch=$1
+
+ if test -z "$2"
+ then
+ set x "$ref_stash@{0}"
+ fi
+ stash=$2
+
+ git-checkout -b $branch $stash^ &&
+ apply_stash --index $stash &&
+ drop_stash $stash
+}
+
# Main command set
case "$1" in
list)
@@ -264,6 +281,10 @@ pop)
drop_stash "$@"
fi
;;
+branch)
+ shift
+ apply_to_branch "$@"
+ ;;
*)
if test $# -eq 0
then