Search code examples
gitgit-stash

How can I save all of my Git stashes differences at once?


Suppose I have multiple stashes in a local repository. When calling git stash list I get a list:

stash@{0}: work done on branch master
stash@{1}: work done on branch a001
stash@{2}: work done on branch a123
stash@{3}: work done on branch a233
stash@{4}: work done on branch a444
...

How could I save each of the diffs of each stash into separate files, all at once?


Solution

  • This should do the trick:

    git stash list | sed 's/\//\_/g'|sed 's/ /\_/g' | awk -F ":" '{ system("git stash show -p " $1 " >> " $1$2$3 ".diff" ) }'
    

    It will create the following files:

    stash@{0}_work_done_on_branch_master.diff
    stash@{1}_work_done_on_branch_a001.diff
    stash@{2}_work_done_on_branch_a123.diff
    stash@{3}_work_done_on_branch_a233.diff
    stash@{4}_work_done_on_branch_a444.diff