Created
January 9, 2024 13:10
-
-
Save icai/b44b25c52514639722fe69866cbcf9d8 to your computer and use it in GitHub Desktop.
Git File Diff Script
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
#!/bin/bash | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
# echo "Enter the first commit hash:" | |
# read commit1 | |
# echo "Enter the second commit hash:" | |
# read commit2 | |
max_log_entries=30 | |
commit_log=$(git log --oneline --abbrev-commit -n $max_log_entries --pretty=format:"%h %s" $branch) | |
# Display commit log for user selection | |
PS3="Select two commits for file changes: " | |
options=() | |
IFS=$'\n' | |
select commit_info in $commit_log; do | |
options+=("$commit_info") | |
if [ ${#options[@]} -eq 2 ]; then | |
break | |
fi | |
done | |
unset IFS | |
# Get hash values of the two selected commits | |
commit1=$(echo ${options[0]} | awk '{print $1}') | |
commit2=$(echo ${options[1]} | awk '{print $1}') | |
mkdir -p diff | |
files=$(git diff --name-only $commit1 $commit2) | |
# copy files to diff folder | |
for file in $files | |
do | |
# get relative path | |
relative_path=$(dirname $file) | |
# create folder | |
mkdir -p diff/$relative_path | |
# copy file | |
cp $file diff/$relative_path | |
done | |
echo "Modified files copied to diff folder." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment