Created
December 6, 2016 08:34
-
-
Save Shrulik/1e3bade3c09bf4151ff2d1ffb874e18d to your computer and use it in GitHub Desktop.
Git File Contention - Simple bash script to list the $n files with the most commits in a git repo
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 | |
# Source of most of this code : http://stackoverflow.com/questions/5669621/git-find-out-which-files-have-had-the-most-commits | |
if [[ $# -ne 1 ]]; then | |
echo " | |
Usage : Please enter a single number argument to see this number of the highest contention ( most commited ) | |
files in the current git repository. | |
" | |
exit 4 | |
fi | |
re='^[0-9]+$' | |
counter=$1 | |
if ! [[ $counter =~ $re && $counter -gt 0 ]] ; then | |
exit 5 | |
fi | |
git rev-list --objects --all | awk '$2' | sort -k2 | uniq -cf1 | sort -rn | | |
while read frequency sample path && [ "$counter" -gt 0 ] | |
do | |
[ "blob" == "$(git cat-file -t $sample)" ] && echo -e "$frequency\t$path" && ((counter--)) ; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment