#!/bin/bash
# 获取上一个和当前提交的哈希
PREV_COMMIT=$(git rev-parse HEAD^)
CURRENT_COMMIT=$(git rev-parse HEAD)
ARCHIVE_DIR="archive/diffs"
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
DIFF_FILE="$ARCHIVE_DIR/diff_${TIMESTAMP}.diff"

# 生成diff文件
echo "$(date)" > "$DIFF_FILE"
echo "$PREV_COMMIT..$CURRENT_COMMIT" >> "$DIFF_FILE"
echo "==========================================" >> "$DIFF_FILE"

git diff --no-color $PREV_COMMIT $CURRENT_COMMIT >> "$DIFF_FILE"
echo $DIFF_FILE
git add $DIFF_FILE
