#!/usr/bin/env bash # Display changes made to a file in all the active branches if [[ $1 == "" ]] ; then echo "branches-diff " 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