How to remove range of git stash?

前端 未结 4 1755
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 02:07

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:

4条回答
  •  灰色年华
    2021-01-04 02:41

    If you want to delete stash 1 to 3,just go to shell and type the following command:

    for n in {1..3}
    do
    git stash drop stash@{1}   
    done
    

    Output

    Dropped stash@{1} (79f369e9c4ce8348af8bd2da63f384cc7d02655e)
    Dropped stash@{1} (744d2fc40e25f2db1bdc182d41f6eb9134957df4)
    Dropped stash@{1} (7f9989207a675549866ab1fc7b15082eb4161e9f)
    

    As git stash uses stack structure, each time you drop nth index, stack indexes decreases by 1. So eventually, you end up dropping stashes 1 to 3. So, like this you can also drop a stash of length n just iterating like :

    for n in {1..n}
    do
    git stash drop stash@{1}   
    done
    

提交回复
热议问题