Search code examples
gitgit-stash

How to take backup of multiple stash?


I understand that we can use git stash show -p > stash.diff to take backup of a stash.

Now I want to take backup of at least 20 stashes. What's a good way to take backup of all the stashes?


Solution

  • This snippet will list the IDs of all your existing stashes, and then create separate diff files for each.

    for stash in `git stash list | awk -F':' '{print $1}'`
    do
        git stash show $stash -p > $stash.diff
    done