Skip to content

Commit e25d5f9

Browse files
drafnelgitster
authored andcommitted
git-stash: add new 'drop' subcommand
This allows a single stash entry to be deleted. It takes an optional argument which is a stash reflog entry. If no arguments are supplied, it drops the most recent stash entry. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 55f1056 commit e25d5f9

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Documentation/git-stash.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-stash - Stash the changes in a dirty working directory away
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git-stash' (list | show [<stash>] | apply [<stash>] | clear)
11+
'git-stash' (list | show [<stash>] | apply [<stash>] | clear | drop [<stash>])
1212
'git-stash' [save [<message>]]
1313

1414
DESCRIPTION
@@ -85,6 +85,11 @@ clear::
8585
Remove all the stashed states. Note that those states will then
8686
be subject to pruning, and may be difficult or impossible to recover.
8787

88+
drop [<stash>]::
89+
90+
Remove a single stashed state from the stash list. When no `<stash>`
91+
is given, it removes the latest one. i.e. `stash@\{0}`
92+
8893

8994
DISCUSSION
9095
----------

git-stash.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# Copyright (c) 2007, Nanako Shiraishi
33

4-
USAGE='[ | save | list | show | apply | clear | create ]'
4+
USAGE='[ | save | list | show | apply | clear | drop | create ]'
55

66
SUBDIRECTORY_OK=Yes
77
OPTIONS_SPEC=
@@ -196,6 +196,28 @@ apply_stash () {
196196
fi
197197
}
198198

199+
drop_stash () {
200+
have_stash || die 'No stash entries to drop'
201+
202+
if test $# = 0
203+
then
204+
set x "$ref_stash@{0}"
205+
shift
206+
fi
207+
# Verify supplied argument looks like a stash entry
208+
s=$(git rev-parse --revs-only --no-flags "$@") &&
209+
git rev-parse --verify "$s:" > /dev/null 2>&1 &&
210+
git rev-parse --verify "$s^1:" > /dev/null 2>&1 &&
211+
git rev-parse --verify "$s^2:" > /dev/null 2>&1 ||
212+
die "$*: not a valid stashed state"
213+
214+
git reflog delete --updateref --rewrite "$@" &&
215+
echo "Dropped $* ($s)" || die "$*: Could not drop stash entry"
216+
217+
# clear_stash if we just dropped the last stash entry
218+
git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash
219+
}
220+
199221
# Main command set
200222
case "$1" in
201223
list)
@@ -230,6 +252,10 @@ create)
230252
fi
231253
create_stash "$*" && echo "$w_commit"
232254
;;
255+
drop)
256+
shift
257+
drop_stash "$@"
258+
;;
233259
*)
234260
if test $# -eq 0
235261
then

0 commit comments

Comments
 (0)