Skip to content

Instantly share code, notes, and snippets.

@toru-hamaguchi
Forked from anonymous/git-export.sh
Created January 8, 2011 01:23
Show Gist options
  • Select an option

  • Save toru-hamaguchi/770408 to your computer and use it in GitHub Desktop.

Select an option

Save toru-hamaguchi/770408 to your computer and use it in GitHub Desktop.
Export files.
#!/bin/sh -
IFS="
"
OPTIONS_KEEPDASHDASH=
OPTIONS_SPEC="\
git export <options> <rev>{0,2}
--
o= Export directory.
"
SUBDIRECTORY_ON="Yes"
. git-sh-setup
# Process options.
if [ $# -eq 0 ] ; then
usage
fi
# Set default parameter.
output="./export"
while getopts "o:" opt
do
case ${opt} in
o)
output=${OPTARG}
shift `expr ${OPTIND} - 1`
;;
\?)
exit 1
;;
esac
done
if [ "$1" = "--" ] ; then
shift
fi
from="$1"
to="$2"
# Set export dir.
now=`date +%Y%m%d%H%M%S`
export="${output}/${now}"
# Export differences.
for file in `git diff --name-only ${from} ${to}`
do
if [ -e ${file} ] ; then
dir=`dirname "${export}/${file}"`
if [ ! -d ${dir} ] ; then
`mkdir -p ${dir}`
fi
`cp ${file} ${export}/${file}`
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment