Skip to content

Instantly share code, notes, and snippets.

@zdennis
Last active January 25, 2022 22:36
Show Gist options
  • Save zdennis/ec5cfa685a1eed7e92e987be2a0c0738 to your computer and use it in GitHub Desktop.
Save zdennis/ec5cfa685a1eed7e92e987be2a0c0738 to your computer and use it in GitHub Desktop.
Git top contributors by file
#!/usr/bin/env ruby
#
# Prints out top 5 contributors per file (as determined by # of commits) on every file in the repository
#
files = `git ls-files`.lines.map(&:chomp)
stats_by_file = {}
files.each_with_index do |file, index|
puts "On #{index+1} of #{files.length}: #{file}"
contributions = `git shortlog #{file} --summary --email --numbered`.lines.map(&:chomp)
stats_by_file[file] = contributions[0..4]
stats_by_file[file].each do |contribution|
puts " #{contribution}"
end
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment