Skip to content

Instantly share code, notes, and snippets.

@solbisio
Created June 19, 2018 15:05
Show Gist options
  • Save solbisio/ad1e31b8bb5318dd87d28a8577c62445 to your computer and use it in GitHub Desktop.
Save solbisio/ad1e31b8bb5318dd87d28a8577c62445 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Export Git Diff"
read -p "Export Start Commit ID: " input1
read -p "Export End Commit ID: " input2
commitIdStart="${input1}"
if [ "${input2}" == "" ]; then
commitIdEnd="HEAD"
else
commitIdEnd="${input2}"
fi
echo "Start ID: $commitIdStart"
echo "End ID: $commitIdEnd"
#Create Export Folder
now=$(date +%Y%m%d_%H%M%S)
#echo "Current date: $now"
dirpath="GitExport/$now"
echo "Export Path:$dirpath"
mkdir -p $dirpath
#Get File List
files=$(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $commitIdStart $commitIdEnd);
#echo $files;
for item in $files ; do
echo "Copy: $item"
## For Linux (Todo Test)
newdir=$(dirname $item)
mkdir -p "$dirpath/$newdir"
cp "$item" "$dirpath/$item"
# For Mac OS
# ditto "$item" "$dirpath/$item"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment