#!/bin/bash # This script finds the files with the most changes in a Git repository, tracking renames and excluding binary files and files with zero changes # Check for the presence of a Git repository if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then echo "This script must be run inside a Git repository." exit 1 fi # Create a temporary file to store changes count temp_file=$(mktemp) # Loop through all files in the Git history, excluding binaries git ls-tree -r --name-only HEAD | while read file; do if [ -n "$file" ]; then # Use git diff to check if the file is binary if ! git diff --numstat -- "$file" | grep -q '^-\s-\s'; then # Count changes for each non-binary file, tracking renames changes=$(git log --follow --numstat --format="%n" -- "$file" | awk '{ add += $1; del += $2 } END { print add + del }') if [ "$changes" -ne 0 ]; then echo "$changes $file" >> "$temp_file" fi fi fi done # Sort the results numerically and reverse sort -nr "$temp_file" | awk '!seen[$2]++' | head -n 30 | while read changes file; do # Determine the emoji based on the count of changes if [ "$changes" -ge 10000 ]; then emoji="โ›”๏ธ" elif [ "$changes" -ge 5000 ]; then emoji="๐Ÿงจ" elif [ "$changes" -ge 2500 ]; then emoji="๐Ÿšจ" elif [ "$changes" -ge 1000 ]; then emoji="โ€ผ๏ธ" elif [ "$changes" -ge 500 ]; then emoji="โš ๏ธ" elif [ "$changes" -ge 250 ]; then emoji="๐Ÿ””" else emoji="โœ…" fi echo "$emoji $changes $file" done # Clean up the temporary file rm "$temp_file"