Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
git-stats

Ever wondered how much who adds/removes, its time to find out :D (those are real stats, i just obfuscated the names )

###Results

Git scores (in LOC):
mr-add              :  +482273       -9466
justu               :  +286250       -159905
grosser             :  +152384       -323344
another             :  +121257       -82116
naames              :  +104577       -13591
justfor             :  +68716        -72446
example             :  +7795         -4987
andeven             :  +5100         -1730
morenow             :  +4225         -2764
finish              :  +17           -19

###Install Copy init git_stats.rb and ruby git_stats.rb (you can add the names of people who commit with different users into the ’same’ array)

#!/usr/bin/env ruby
t = Time.now
#same = [['name-a','name-b'],['mr fred','fred']]
same = []
pipe = open('|git log --pretty=format:"A:%an" --shortstat --no-merges')
author = "unknown"
stats = {}
loop do
line = pipe.readline rescue break
if line =~ /^A\:(.*)$/
author = $1
found = same.detect{|a| a.include?(author)}
author = found.first if found
next
end
if line =~ /files changed, (\d+) insertions\(\+\), (\d+) deletions/
stats[author] ||= Hash.new(0)
stats[author]['+']+=$1.to_i
stats[author]['-']+=$2.to_i
print '.'
end
end
puts "\nGit scores (in LOC):"
puts stats.sort_by{|a,d| -d['+'] }.map{|author, data| "#{author.ljust(20)}: +#{data['+'].to_s.ljust(10)} -#{data['-'].to_s.ljust(10)} " } * "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.