Skip to content

Instantly share code, notes, and snippets.

@oti
Created December 10, 2015 05:07
Show Gist options
  • Save oti/b2f98e29b36d7e768a38 to your computer and use it in GitHub Desktop.
Save oti/b2f98e29b36d7e768a38 to your computer and use it in GitHub Desktop.
gitで差分ファイルを抽出する
# http://qiita.com/kaminaly/items/28f9cb4e680deb700833
# --diff-filter=Dがあると期待通りの抽出ができないのでそれを削除している
function git_diff_archive()
{
local diff=""
local h="HEAD"
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 --name-only ${diff}"
fi
git archive --format=zip --prefix=root/ $h `eval $diff` -o archive.zip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment