Last Updated: February 25, 2016
·
2.204K
· stevehalford

Git time tracking

#!/usr/bin/ruby

command = '/usr/bin/git --no-pager log --oneline'

ARGV.each do|a|
 if a.match(/^--after/) 
 command += ' ' + a
 end
end

hours = 0
begin
 output = `#{command}`

 commits = output.split("\n")
 commits.each do |line|

 line.scan(/t\[(.*)\]/) do |r| 
 r.each { |h| hours += h.to_f }
 end

 end
 print "Total: #{hours}hrs\n"
rescue => e
 puts e.message
 exit
end 

A script for time tracking using git commits.

  • Save the script as an executable (I've called it git-tt)
  • Add tags to your commit messages with the amount of hours you've spent, eg. "Implemented foobar feature t[1.5]."
  • Run git tt from a git repo to show total hours for that repo.
  • Add '--after="2010-03-15"' to show total for commits since the date

1 Response
Add your response

good tips ! thank's

over 1 year ago ·