Skip to content

Instantly share code, notes, and snippets.

@chetan
Created January 16, 2013 17:50
Show Gist options
  • Save chetan/4549183 to your computer and use it in GitHub Desktop.
Save chetan/4549183 to your computer and use it in GitHub Desktop.
show the last commit for all branches
#!/usr/bin/env ruby
branches = `git branch -a`
exit 1 if $?.to_i != 0
branches = branches.split(/\n/).map{ |b| b.gsub(/(\*|\->.*$|^\s+| +$)/, '') };
l = branches.max_by{ |b| b.length }.length
branches.each do |branch|
pad = " " * (l-branch.length)
STDOUT.write("#{pad}#{branch} ")
format = [
"%Cred%h%Creset - ", # commit
"%Cgreen(%cr)", # age
"%Creset %s ", # log
"%C(bold blue)<%an>", # user
"%C(yellow)%d", # branch info
"%Creset" # reset
].join("")
system("git --no-pager log -1 --color --pretty=format:'#{format}' --abbrev-commit #{branch}")
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment