Skip to content

Instantly share code, notes, and snippets.

@brentroady
Created October 11, 2021 17:24
Show Gist options
  • Save brentroady/06d3476699e1ac6e14a5dcfbb05c3e23 to your computer and use it in GitHub Desktop.
Save brentroady/06d3476699e1ac6e14a5dcfbb05c3e23 to your computer and use it in GitHub Desktop.
Copy stashes in all sub-folders into a destination folder
#! /bin/bash
copy-stashes() {
src=$1
dest=$2
current_directory=$(pwd)
cd $src
stashes=$(git stash list)
IFS=$'\n'
stash_messages=()
for stash in $stashes; do
stash_number=$(echo $stash | cut -d ':' -f 1 | sed 's/^stash@{\([0-9][0-9]*\)}/\1/g')
stash_message=$(echo $stash | cut -d ':' -f 2- | xargs)
stash_messages+=($stash_message)
git --no-pager stash show "stash@{$stash_number}" -p >"../${dest}/${src}_patch_${stash_number}"
done
IFS=$' '
echo "Number of stashes: ${#stash_messages[@]}"
cd $current_directory
}
for D in *; do
if [ -d "${D}" ]; then
copy-stashes ${D} $1;
fi;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment