んー、もうちょっと何とかならんか、とも思うが、目的は達したみたいなので…
#!/bin/bash
patches_dir="/tmp/patches"
if [ -e $patches_dir ]; then
mkdir $patches_dir
fi
cd /etc
last_commit=`git log | head -1 | awk '{print $2}'`
for file_path in `find /etc -type d -name '.git' -prune -o -type f`; do
echo "Extracting diff of $file_path..."
first_commit=`git log --diff-filter=A -- $file_path | head -1 | awk '{print $2}'`
gitdiff=`git diff-tree -p $first_commit $last_commit $file_path`
if [ "$gitdiff" != "" ]; then
dir_path=`dirname $file_path`
mkdir -p $patches_dir$dir_path
echo -e "$gitdiff" > $patches_dir$file_path.patch
fi
done