Skip to content

Instantly share code, notes, and snippets.

@katsuobushiFPGA
Last active October 14, 2018 09:57
Show Gist options
  • Save katsuobushiFPGA/9711d4884e543aee4c5b53b7cb74bbc1 to your computer and use it in GitHub Desktop.
Save katsuobushiFPGA/9711d4884e543aee4c5b53b7cb74bbc1 to your computer and use it in GitHub Desktop.
Gitプロジェクトのあるコミットからあるコミットの変更後 変更前ソースの差分を取得するシェル
#!/bin/bash
# archive.sh
# 変更後 変更前ソースの差分を格納するシェルです。
#
# 引数1 : 抽出したいコミットID from
# 引数2 : 抽出したいコミットID to
# 引数3 ファイルのzip名
# 引数4 プロジェクトフォルダのフルパス
# 作業用ディレクトリ ここに吐かせる
WORK_DIR='C:/tmp'
cd $4
#差分リスト
git diff --stat-width=800 --name-status $1 $2 > $WORK_DIR/diff_list.txt
# 変更後ソースの格納
git archive $2 --format=zip --prefix=fix/ `git diff --diff-filter=ACMR --name-only $1 $2` -o $WORK_DIR/$3_fix.zip
# 変更前ソースの格納
git archive $1 --format=zip --prefix=org/ `git diff --diff-filter=ACMR --name-only $1 $2` -o $WORK_DIR/$3_org.zip
cd $WORK_DIR
unzip $3_fix.zip
unzip $3_org.zip
#格納フォルダ作成
zip $3.zip -r fix org diff_list.txt
#不要ファイル削除
rm -fR fix/
rm -fR org/
rm -f $3_fix.zip
rm -f $3_org.zip
rm -fR $3/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment