Skip to content

Instantly share code, notes, and snippets.

@JasonGiedymin
Created May 28, 2017 03:10
Show Gist options
  • Save JasonGiedymin/b58958360f25433899aa7f964e2c8e26 to your computer and use it in GitHub Desktop.
Save JasonGiedymin/b58958360f25433899aa7f964e2c8e26 to your computer and use it in GitHub Desktop.
Git cherry pick out files into another directory with full paths retained.
#!/usr/bin/env bash
#
# Author: _j_a_s_o_n_g_at_a_p_a_c_h_e_dot_org
# License: GNU GPLv3
#
set -e
if [ -z "$1" ]; then
echo "Please supply param 1 as the git hash which to cheery pick. Now exiting..."
exit 1
fi;
GIT_HASH=$1
if [ -z "$2" ]; then
echo "Please supply param 2 as the fully qualified destination. Now exiting..."
exit 1
fi;
DEST=$2
for file in `git diff-tree --no-commit-id --name-only -r $GIT_HASH`; do;
folder=$(dirname $file)
mkdir -p $DEST/$folder
cp "$file" $DEST/$folder
done
echo "Done. You'll find the files cherry picked with pull paths in [$DEST]."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment