-
-
Save toru-hamaguchi/770408 to your computer and use it in GitHub Desktop.
Export files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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