Skip to content

Instantly share code, notes, and snippets.

@jamster
Created March 22, 2011 17:32
Show Gist options
  • Save jamster/881641 to your computer and use it in GitHub Desktop.
Save jamster/881641 to your computer and use it in GitHub Desktop.
quick script to parse git logs and turn them to a data structure
# Usage:
# git log | ruby git_commit_parser.rb
# https://gist.github.com/881641
# By: Jason Amster
# jayamster@gmail.com
require 'rubygems'
require 'pp'
logs = STDIN.read
logs = logs.split("commit ")
logs.shift
logs = logs.map do |log|
l = log.split("\n")
commit = l.shift
author = l.shift.to_s.split("Author: ")[1]
x = author.to_s.split(" ")
email = x.pop
name = x.join(' ')
date = l.shift.to_s.split("Date: ")[1].to_s.strip
comments = l.join("\n")
{
:commit => commit,
:author => author,
:name => name,
:email => email,
:date => date,
:comments => comments
}
end
pp logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment