How can I delete all of my Git stashes at once?

前端 未结 7 2095
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 14:42

How can I delete all of my Git stashes at once?

Specifically I mean, with typing in one command.

相关标签:
7条回答
  • 2020-12-22 14:47

    There are two ways to delete a stash:

    1. If you no longer need a particular stash, you can delete it with: $ git stash drop <stash_id>.
    2. You can delete all of your stashes from the repo with: $ git stash clear.

    Use both of them with caution, it maybe is difficult to revert the once deleted stashes.

    Here is the reference article.

    0 讨论(0)
  • 2020-12-22 14:48

    this command enables you to look all stashed changes.

    git stash list
    

    Here is the following command use it to clear all of your stashed Changes

    git stash clear
    

    Now if you want to delete one of the stashed changes from stash area

    git stash drop stash@{index}   // here index will be shown after getting stash list.
    

    Note : git stash list enables you to get index from stash area of git.

    0 讨论(0)
  • 2020-12-22 14:49

    I had another requirement like only few stash have to be removed, below code would be helpful in that case.

    #!/bin/sh
    for i in `seq 5 8`
    do
       git stash drop stash@{$i}
    done
    

    /* will delete from 5 to 8 index*/

    0 讨论(0)
  • 2020-12-22 14:50

    I wanted to keep a few recent stashes, but delete everything else.

    Because all stashes get renumbered when you drop one, this is actually easy to do with while. To delete all stashes older than stash@{19}:

    while git stash drop 'stash@{20}'; do true; done
    
    0 讨论(0)
  • 2020-12-22 14:54

    To delete all stashes older than 40 days, use:

    git reflog expire --expire-unreachable=40.days refs/stash
    

    Add --dry-run to see which stashes are deleted.

    See https://stackoverflow.com/a/44829516/946850 for an explanation and much more detail.

    0 讨论(0)
  • 2020-12-22 15:08

    if you want to remove the latest stash or at any particular index -

    git stash drop type_your_index

    > git stash list
    
      stash@{0}: abc
      stash@{1}: xyz
      stash@{1}: pqr
    
    > git stash drop 0
    
      Dropped refs/stash@{0}
    
    > git stash list
    
      stash@{0}: xyz
      stash@{1}: pqr
    

    if you want to remove all the stash at once -

    > git stash clear
    >
    
    > git stash list
    >
    

    Warning : Once done you can not revert back your stash

    0 讨论(0)
提交回复
热议问题