Skip to content

Instantly share code, notes, and snippets.

@sos4nt
Created February 24, 2012 14:11
Show Gist options
  • Save sos4nt/1901171 to your computer and use it in GitHub Desktop.
Save sos4nt/1901171 to your computer and use it in GitHub Desktop.
Extracts changed files from a specified commit into an output directory
#!/bin/sh
set -e
usage() {
echo "usage: git-extract.sh commit output-directory"
}
extract() {
FILES=`git diff-tree --oneline --no-commit-id --name-only -r $1`
for file in $FILES
do
dirname=`dirname "$file"`
`mkdir -p "$2/$dirname"`
`cp "$file" "$2/$file"`
done
}
if [ $# -ne 2 ]
then
usage
exit 1
else
extract $1 $2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment