Last active
March 5, 2025 07:12
-
-
Save fastfingertips/c0b32d884b8b77e7c948662969416d7f to your computer and use it in GitHub Desktop.
This script lists files in a Git repository with their last commit time (ISO format) and total commit count, helping identify the most frequently updated 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 | |
# Git Repository File Analysis Utility | |
# | |
# DESCRIPTION: | |
# Analyzes Git repository files with: | |
# - Last commit date | |
# - Total commit count per file | |
# | |
# USAGE: | |
# ./git-file-analyzer.sh [OPTIONS] | |
# | |
# OPTIONS: | |
# -n NUMBER Show top N recently updated files | |
# -a Sort in ascending order (oldest first) | |
# | |
# EXAMPLES: | |
# ./git-file-analyzer.sh # Default: newest files first | |
# ./git-file-analyzer.sh -n 10 # Top 10 recently updated files | |
# ./git-file-analyzer.sh -a # All files, oldest first | |
# CONFIGURATION | |
SORT_ORDER="-r" | |
LIMIT="" | |
# ARGUMENT PARSING | |
while getopts "n:a" opt; do | |
case $opt in | |
n) LIMIT="$OPTARG";; | |
a) SORT_ORDER="";; | |
esac | |
done | |
# REPOSITORY VALIDATION | |
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || { | |
echo "Error: Not a Git repository!"; | |
exit 1; | |
} | |
# FILE ANALYSIS | |
analyze_files() { | |
git ls-files | while read -r file; do | |
[ -d "$file" ] && continue | |
last_date=$(git log -1 --format="%cd" --date=iso -- "$file" | cut -d" " -f1,2) | |
commits=$(git log --oneline -- "$file" | wc -l) | |
printf "%-16s %5d %s\n" "$last_date" "$commits" "$file" | |
done | |
} | |
# OUTPUT | |
if [ -n "$LIMIT" ]; then | |
analyze_files | sort $SORT_ORDER | head -n "$LIMIT" | |
else | |
analyze_files | sort $SORT_ORDER | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment