Skip to content

Instantly share code, notes, and snippets.

@mcansky
Created January 30, 2011 01:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mcansky/802396 to your computer and use it in GitHub Desktop.
Save mcansky/802396 to your computer and use it in GitHub Desktop.
simple ruby git changelog generator
# simple rake task to output a changelog between two commits, tags ...
# output is formatted simply, commits are grouped under each author name
#
desc "generate changelog with nice clean output"
task :changelog, :since_c, :until_c do |t,args|
since_c = args[:since_c] || `git tag | head -1`.chomp
until_c = args[:until_c]
cmd=`git log --pretty='format:%ci::%an <%ae>::%s::%H' #{since_c}..#{until_c}`
entries = Hash.new
changelog_content = String.new
cmd.split("\n").each do |entry|
date, author, subject, hash = entry.chomp.split("::")
entries[author] = Array.new unless entries[author]
day = date.split(" ").first
entries[author] << "#{subject} (#{hash})" unless subject =~ /Merge/
end
# generate clean output
entries.keys.each do |author|
changelog_content += author + "\n"
entries[author].reverse.each { |entry| changelog_content += " * #{entry}\n" }
end
puts changelog_content
end
#!/usr/bin/env ruby
# output a minimal changelog using git commit first line
# first and second args will be used as "since".."until" args for git log command
# based on http://snipplr.com/view.php?codeview&id=6261
# output is formatted simply, commits are grouped under each author name
#
cmd=`git log --pretty='format:%ci::%an <%ae>::%s::%H' #{ARGV[0]}..#{ARGV[1]}`
entries = Hash.new
changelog_content = String.new
cmd.split("\n").each do |entry|
date, author, subject, hash = entry.chomp.split("::")
entries[author] = Array.new unless entries[author]
day = date.split(" ").first
entries[author] << "#{subject} (#{hash})" unless subject =~ /Merge/
end
# generate clean output
entries.keys.each do |author|
changelog_content += author + "\n"
entries[author].reverse.each { |entry| changelog_content += "\t* #{entry}\n" }
end
puts changelog_content
@cdesch
Copy link

cdesch commented Sep 29, 2016

the git log command has changed since then.

You may want to change the lines:

 #Rake
 #{since_c}..#{until_c}   

 #stand alone
 #{ARGV[0]}..#{ARGV[1]}

To:

 #Rake
 --after=#{since_c} --before=#{until_c}

 #stand alone
 --after=#{ARGV[0]} --before=#{ARGV[1]}

I've got it here in a fork if you want to copy it https://gist.github.com/cdesch/e38af06b4740817de067ba30915d0697

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment