Search code examples
gitgit-stash

How to remove range of git stash?


I want to remove all stash'es, except most recent, from git stash list.

E.g. I want to remove stash 1 to 3 in a single git command:

stash@{0}: On master: Test related changes
stash@{1}: On master: Tets
stash@{2}: On master: Integrate bunyan logging and http2
stash@{3}: On master: Integrate bunyan logging and http2

I checked this answer https://stackoverflow.com/a/5737041/3878940, but its applicable to delete only a single stash. Is there any git command to delete a range of stashes?


Solution

  • Short answer: no.

    Slightly longer answer: no, but it's trivial. You want to drop stashes 1, 2, and 3. When you drop stash #1, stashes 2 and 3 become stashes 1 and 2 respectively. When you drop the new stash #1, stash #2 (which was #3 originally) becomes stash #1. Therefore, to drop three stashes, starting with #1, simply drop stash #1 three times.