File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ git-stash - Stash the changes in a dirty working directory away
88SYNOPSIS
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
1414DESCRIPTION
@@ -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
8994DISCUSSION
9095----------
Original file line number Diff line number Diff line change 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
66SUBDIRECTORY_OK=Yes
77OPTIONS_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
200222case " $1 " in
201223list)
@@ -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
You can’t perform that action at this time.
0 commit comments