Skip to content

Instantly share code, notes, and snippets.

@harapeko
Created April 21, 2019 08:04
Show Gist options
  • Save harapeko/d5db8e3cc24098774b5165a193dc9f0f to your computer and use it in GitHub Desktop.
Save harapeko/d5db8e3cc24098774b5165a193dc9f0f to your computer and use it in GitHub Desktop.
git diff archive
#!/bin/sh
# ---
# git diff archive
#
# HOWTO
# ./gda.sh [from]
# ./gda.sh [from] [to]
# toを省略した場合はHEADがのコミットハッシュが使われます
#
# OUTPUT
# ./dist/prod_[from]_[to].zip
# ---
# check arg
if [ $# -lt 1 ]; then
echo "引数例外:引数が$#個です。" 1>&2
echo "下記のように実行してください:" 1>&2
echo "./gda.sh [from]" 1>&2
echo "./gda.sh [from] [to]" 1>&2
exit 1
fi
# get arg
FROM_RIVISION=$1
TO_RIVISION=HEAD
if [ "$2" ]; then
TO_RIVISION=$2
fi
# set short commit hash
FROM_RIVISION=`git log $FROM_RIVISION --pretty="%h" | head -1`
TO_RIVISION=`git log $TO_RIVISION --pretty="%h" | head -1`
# set path
ARCHIVE_PATH=$(pwd)/dist/"prod_${FROM_RIVISION}_${TO_RIVISION}.zip"
# archive
DIFF_LIST_PATH=`git diff --name-only $TO_RIVISION $FROM_RIVISION --diff-filter=ACMR`
git archive $TO_RIVISION $DIFF_LIST_PATH -o $ARCHIVE_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment