生成commitId与其父commitId间的文件差异文件树
#!/bin/bash
#
# 用于生成目标commitId与其父commitId间文件差异
#
commit_id=$1 # 输入目标commit的哈希值
old_dir="old_version"
new_dir="new_version"# 创建目录
mkdir -p "$old_dir" "$new_dir"# 获取差异文件列表
files=$(git diff --name-only "${commit_id}^" "$commit_id")# 导出文件
for file in $files; do# 父commit版本mkdir -p "$old_dir/$(dirname "$file")"git show "${commit_id}^:$file" > "$old_dir/$file" 2>/dev/null || echo "[跳过] 父提交中不存在: $file"# 当前commit版本mkdir -p "$new_dir/$(dirname "$file")"git show "${commit_id}:$file" > "$new_dir/$file" 2>/dev/null || echo "[跳过] 当前提交中不存在: $file"
donemv "$old_dir" "$commit_id"_"$old_dir"
mv "$new_dir" "$commit_id"_"$new_dir"