Last active
February 19, 2016 02:11
-
-
Save wadackel/06f2a67c96b50f81b2e6 to your computer and use it in GitHub Desktop.
gitで差分ファイルの抽出用関数
This file contains 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 | |
function git_diff_archive() | |
{ | |
local OPTIND OPTARG OPT | |
local dateTime=`date '+%Y%m%d%H%M'` | |
local mode="AMCRD" | |
local diff="" | |
local h="HEAD" | |
usage() | |
{ | |
cat <<_EOT_ | |
Usage: | |
git_diff_archive [-m mode] commit_id [old_commit_id] | |
Description: | |
Generate to the zip file in git diff command. | |
Options: | |
-m mode [A|M|C|R|D] (Defaut:AMCRD) | |
-h help | |
_EOT_ | |
} | |
# parse opts | |
while getopts "m:h" OPT | |
do | |
case $OPT in | |
m) | |
mode=$OPTARG | |
;; | |
h) | |
usage | |
return | |
;; | |
\?) | |
usage | |
return | |
;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
# parse commit_id | |
if [ $# -eq 1 ]; then | |
if expr "$1" : '[0-9]*$' > /dev/null ; then | |
diff="HEAD HEAD~${1}" | |
else | |
diff="HEAD ${1}" | |
fi | |
elif [ $# -eq 2 ]; then | |
diff="${1} ${2}" | |
h=$1 | |
fi | |
if [ "$diff" != "" ]; then | |
diff="git diff --diff-filter=${mode} --name-only ${diff}" | |
fi | |
git archive --format=zip --prefix=${PWD##*/}/ $h `eval $diff` -o ${PWD##*/}-$dateTime.zip | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
調整箇所
以下、参考サイトからの変更箇所。
--prefix
には現在のディレクトリ名を (展開後に分かりやすいように)--diff-filter
の値を-m
オプションで別途指定できるように-h
オプションで簡単なヘルプを参照参考