Skip to content

Commit 367ea19

Browse files
committed
Merge branch 'js/stash-dwim' into tr/reset-checkout-patch
* commit 'tr/reset-checkout-patch^^2': Make 'git stash -k' a short form for 'git stash save --keep-index'
2 parents dda1f2a + ea41cfc commit 367ea19

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

Documentation/git-stash.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ SYNOPSIS
1313
'git stash' drop [-q|--quiet] [<stash>]
1414
'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
1515
'git stash' branch <branchname> [<stash>]
16-
'git stash' [save [--patch] [--[no-]keep-index] [-q|--quiet] [<message>]]
16+
'git stash' [save [--patch] [-k|--[no-]keep-index] [-q|--quiet] [<message>]]
17+
'git stash' [-k|--keep-index]
1718
'git stash' clear
1819
'git stash' create
1920

git-stash.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ USAGE="list [<options>]
77
or: $dashless drop [-q|--quiet] [<stash>]
88
or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>]
99
or: $dashless branch <branchname> [<stash>]
10-
or: $dashless [save [--keep-index] [-q|--quiet] [<message>]]
10+
or: $dashless [save [-k|--keep-index] [-q|--quiet] [<message>]]
11+
or: $dashless [-k|--keep-index]
1112
or: $dashless clear"
1213

1314
SUBDIRECTORY_OK=Yes
@@ -132,7 +133,7 @@ save_stash () {
132133
while test $# != 0
133134
do
134135
case "$1" in
135-
--keep-index)
136+
-k|--keep-index)
136137
keep_index=t
137138
;;
138139
--no-keep-index)
@@ -405,12 +406,13 @@ branch)
405406
apply_to_branch "$@"
406407
;;
407408
*)
408-
if test $# -eq 0
409-
then
410-
save_stash &&
409+
case $#,"$1" in
410+
0,|1,-k|1,--keep-index)
411+
save_stash "$@" &&
411412
say '(To restore them type "git stash apply")'
412-
else
413+
;;
414+
*)
413415
usage
414-
fi
416+
esac
415417
;;
416418
esac

t/t3903-stash.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,12 @@ test_expect_success 'drop -q is quiet' '
200200
test ! -s output.out
201201
'
202202

203+
test_expect_success 'stash -k' '
204+
echo bar3 > file &&
205+
echo bar4 > file2 &&
206+
git add file2 &&
207+
git stash -k &&
208+
test bar,bar4 = $(cat file),$(cat file2)
209+
'
210+
203211
test_done

0 commit comments

Comments
 (0)