Last active
October 10, 2019 06:25
-
-
Save tohokuaiki/c8e4c2e0058b384ce98657bf5383d5df to your computer and use it in GitHub Desktop.
gitのcommitの差分をファイルに出す。削除ファイルの一覧付き。このファイルはgitリポジトリの直下に置く。SourceTreeのカスタムアクションのために作った。SourceTreeの For SourceTree custom action. 実行にはSourceTree\git_local\bin\bash.exeを使用。
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
ARCHIVE_INFO_FILE=archive_info.txt | |
DELETE_FILES_INFO=deleted_files.txt | |
T_TIME=`date "+%Y%m%d_%H%M%S"` | |
T_DAY=`date "+%Y%m%d"` | |
# $1に新しい方、$2に古い方のハッシュ | |
if [ $# -ne 2 ]; then | |
echo "引数が不正です。コミットは2つ指定してください。" >&2 | |
exit 1 | |
fi | |
if [ $1 = "-1" ]; then | |
echo "未コミットを指定しないでください。" >&2 | |
exit 1 | |
fi | |
# コミット情報の表示 | |
echo "指定したコミット情報" > $ARCHIVE_INFO_FILE | |
echo "From: [古いコミット]" >> $ARCHIVE_INFO_FILE | |
git log --format="%cd - %cn<%ce> %s" -n 1 $2 >> $ARCHIVE_INFO_FILE | |
echo "Until: [新しいコミット]" >> $ARCHIVE_INFO_FILE | |
git log --format="%cd - %cn<%ce> %s" -n 1 $1 >> $ARCHIVE_INFO_FILE | |
# 削除したファイルの提示 | |
echo "[削除したファイル]" > $DELETE_FILES_INFO | |
git diff --diff-filter=D --name-only $2 $1 >> $DELETE_FILES_INFO | |
# 差分抽出 | |
git archive --prefix=$T_DAY/ $1 `git diff --diff-filter=d --name-only $2 $1` -o archive_$T_TIME.tar | |
tar -rf archive_$T_TIME.tar $DELETE_FILES_INFO $ARCHIVE_INFO_FILE | |
gzip archive_$T_TIME.tar | |
rm $DELETE_FILES_INFO $ARCHIVE_INFO_FILE | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
普通にbashでも
bash get_gitdiff.sh new_commit_id old_commit_id
ってやれば行けると思う。