2 - Presenting Git Changes
Result #
#! /run/current-system/sw/bin/bash
cd ..
# Get the total number of commits
commit_count=$(git rev-list --count HEAD)
# Loop through each commit in reverse order (last to first)
for (( i=1; i<=$commit_count; i++ )); do
# Calculate commit hash for the current iteration
commit_hash=$(git rev-list --max-count=1 --skip=$((commit_count - i)) HEAD)
# Get the hash of the previous commit (or an empty string if it's the first commit)
if [ $i -eq 1 ]; then
previous_commit=""
else
previous_commit=$(git rev-list --max-count=1 --skip=$((commit_count - i + 1)) HEAD)
fi
# Generate the diff, using the empty tree for the initial commit if necessary
if [ -z "$previous_commit" ]; then
git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 $commit_hash > "commit_$(printf "%03d" $i)_$(git rev-parse --short $commit_hash).diff"
else
git diff $previous_commit $commit_hash > "commit_$(printf "%03d" $i)_$(git rev-parse --short $commit_hash).diff"
fi
done
echo "Diff files for all commits have been created."
Current Date: December 29, 2024
...