Last active
August 31, 2020 15:39
-
-
Save maxlath/6e3c91a536548a2e52c67706ce79b75d to your computer and use it in GitHub Desktop.
Display changes made to a file in all the active branches
This file contains hidden or 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
#!/usr/bin/env bash | |
# Display changes made to a file in all the active branches | |
if [[ $1 == "" ]] ; then | |
echo "branches-diff <files...|folders...>" | |
exit 1 | |
fi | |
branches_on_origin_remote_with_last_commit_less_than_a_year_ago(){ | |
one_year_ago=$(date -d "-1 year" +%Y-%m-%d) | |
git for-each-ref --format='%(committerdate:iso) %(refname)' --sort -committerdate | \ | |
awk '{if($1>"'$one_year_ago'")print $4}' | \ | |
grep -vE 'HEAD|master' | \ | |
grep origin | \ | |
sed 's|^.*/origin/||' | |
} | |
{ | |
for branch in $(branches_on_origin_remote_with_last_commit_less_than_a_year_ago) ; do | |
branch_start=$(git merge-base master $branch | cut -c 1-7) | |
tmp_file="/tmp/git_branch_diff_${branch_start}_${branch}" | |
git --no-pager diff --color=always $branch_start $branch -- $@ > "$tmp_file" | |
lines_count=$(wc -l "$tmp_file" | awk '{print $1}') | |
if [[ "$lines_count" != "0" ]] ; then | |
echo -e "\n\e[0;44m================\e[0m diff $branch_start - $branch \e[0;44m================\e[0m" | |
cat "$tmp_file"; | |
else | |
echo -e "\e[0;30m================ diff $branch_start - $branch ================\e[0m" | |
fi | |
done | |
} | less -R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment