Skip to content

Instantly share code, notes, and snippets.

@dougharris
Created December 23, 2020 16:09
Show Gist options
  • Save dougharris/a5a1f6a5155ac6c72bc0ae081c1c4cf4 to your computer and use it in GitHub Desktop.
Save dougharris/a5a1f6a5155ac6c72bc0ae081c1c4cf4 to your computer and use it in GitHub Desktop.
Script for exporting git stashes
#!/bin/bash
STASH_DIR="${HOME}/src/stash-patches"
PROJECT=$(basename $(pwd))
mkdir -p "${STASH_DIR}/${PROJECT}"
git stash list | while read -r ref stash
do
name=$(echo $stash | awk -F': ' '{printf("%s", $2);}' | tr -c '[:alnum:]_-' '-' | tr -s '-')
full_path="${STASH_DIR}/${PROJECT}/${name}"
echo "Writing stash '${name}' to ${full_path}"
git stash show "${ref/:/}" -p > "${full_path}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment