Last active
August 29, 2015 14:15
-
-
Save masaru-b-cl/5ada3ccd4ad4627032ca to your computer and use it in GitHub Desktop.
git-archive-diff | コミット間で差分のあるファイルをzipでエクスポートする ( inspired by gitで差分ファイルを抽出する - Qiita http://qiita.com/kaminaly/items/28f9cb4e680deb700833 )
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 | |
| function usage() { | |
| echo "usage: git archive-diff [-o <zip-file-path>]" | |
| echo "usage: git archive-diff <commit> [-o <zip-file-path>]" | |
| echo "usage: git archive-diff <commit> <commit> [-o <zip-file-path>]" | |
| exit 1 | |
| } | |
| OUTPUT_FILE="archive.zip" | |
| if [ $# -gt 0 ] | |
| then | |
| if [ $# -eq 1 ] | |
| then | |
| COMMIT_SRC="HEAD" | |
| COMMIT_DST=$1 | |
| elif [ $# -eq 2 ] | |
| then | |
| if [ $1 = "-o" ] | |
| then | |
| COMMIT_SRC="HEAD" | |
| COMMIT_DST="HEAD~" | |
| OUTPUT_FILE=$2 | |
| else | |
| COMMIT_SRC=$1 | |
| COMMIT_DST=$2 | |
| fi | |
| elif [ $# -eq 3 ] | |
| then | |
| if [ $2 = "-o" ] | |
| then | |
| COMMIT_SRC="HEAD" | |
| COMMIT_DST=$1 | |
| OUTPUT_FILE=$3 | |
| else | |
| usage | |
| fi | |
| elif [ $# -eq 4 ] | |
| then | |
| if [ $3 = "-o" ] | |
| then | |
| COMMIT_SRC=$1 | |
| COMMIT_DST=$2 | |
| OUTPUT_FILE=$4 | |
| else | |
| usage | |
| fi | |
| else | |
| usage | |
| fi | |
| else | |
| COMMIT_SRC="HEAD" | |
| COMMIT_DST="HEAD~" | |
| fi | |
| TARGET_FILES=`git diff --name-only ${COMMIT_SRC} ${COMMIT_DST}` | |
| if [ -z "${TARGET_FILES}" ] | |
| then | |
| echo "No diff files." | |
| exit 1 | |
| fi | |
| git archive --format=zip ${COMMIT_SRC} ${TARGET_FILES} -o ${OUTPUT_FILE} | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment