Skip to content

Instantly share code, notes, and snippets.

@icai
Created January 10, 2024 04:05
Show Gist options
  • Save icai/1a4cd167bb53442fbc16079199e63e3e to your computer and use it in GitHub Desktop.
Save icai/1a4cd167bb53442fbc16079199e63e3e to your computer and use it in GitHub Desktop.
git diff two branches change
#!/bin/bash
max_log_entries=30
# Get the list of branches
branches=$(git for-each-ref --sort='-committerdate:iso8601' --format '%(refname:short)' refs/heads/)
# Display branch list for user selection
PS3="Select two branches for file changes: "
options=()
# IFS=$'\n'
select branch in $branches; do
options+=("$branch")
if [ ${#options[@]} -eq 2 ]; then
break
fi
done
# unset IFS
# Get the commit hashes of the selected branches
commit1=$(git rev-parse ${options[0]})
commit2=$(git rev-parse ${options[1]})
mkdir -p diff
# Use commit hashes for git 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 between selected branches copied to diff folder."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment