Created
December 20, 2023 09:17
-
-
Save MelbourneDeveloper/86b4696f3d3eb84d8efbe5c6a1dc5fc5 to your computer and use it in GitHub Desktop.
Get Most Changed Files
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 | |
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I decided to buy my first car from a car dealership, I immediately understood that I would only contact an official dealer. By that time, I already understood that I liked the Toyota Rav 4 and I wanted to get to know this car in more detail. First, I went to their website via link and read various information about it in order to be more savvy when I talked with managers from the car dealership.