Skip to content

Instantly share code, notes, and snippets.

@dominicgan
Created June 2, 2024 04:11
Show Gist options
  • Save dominicgan/6e6833936f01ab7703c23c11bd1f1ef2 to your computer and use it in GitHub Desktop.
Save dominicgan/6e6833936f01ab7703c23c11bd1f1ef2 to your computer and use it in GitHub Desktop.
Export git stashes into individual files
#!/bin/bash
# To use the script:
# 1. Save the script to a file, for example, export_stashes.sh.
# 2. Make the script executable: chmod +x export_stashes.sh.
# 3. Run the script: ./export_stashes.sh.
# Get the list of all stashes
stashes=$(git stash list)
# Iterate over each stash
index=0
echo "$stashes" | while IFS= read -r stash; do
# Extract stash name
stash_name=$(echo "$stash" | awk '{print $1}' | sed 's/:$//')
echo $stash_name
# Define the output file name
output_file="stash_${index}.diff"
# Export the stash diff to a file
if [ -n "$stash_name" ]; then
git stash show -p "$stash_name" > "$output_file"
echo "Exported $stash_name to $output_file"
index=$((index + 1))
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment