Created
November 13, 2011 19:05
-
-
Save bdunagan/1362507 to your computer and use it in GitHub Desktop.
git log with colors and lines changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See colored 'git log' with lines changes in Terminal on Mac | |
# => * 1234567 - 2001-01-01 - NNNNN - description <user> | |
# Based on http://www.jukie.net/bart/blog/pimping-out-git-log | |
# git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative" | |
# To install as 'gl' alias (not overriding 'git log'): | |
# 1) save this as ~/.gitlog.rb | |
# 2) add to ~/.bash_profile: 'alias gl="ruby ~/.gitlog.rb | more -r"' | |
# Get the pretty log with spaces for the lines changes. | |
commits_cmd = "git log --graph --pretty=format:'%Cred%h%Creset - %Cgreen%ad - -%C(yellow)%d%Creset %s %C(bold blue)<%an>%Creset' --abbrev-commit --date=short" | |
commits=%x[#{commits_cmd}] | |
# Iterate over each commit to replace spaces with lines changed. | |
commits.split("\n").each do |commit| | |
# Get the current commit's hash. | |
hash = /([0-9a-f]{7})/.match(commit) | |
# Get the lines changes for this commit. | |
lines_cmd = "git log #{hash} --shortstat -n 1 | sed -n -e 's/\\([0-9]*\\) files changed, \\([0-9]*\\) insertions(+), \\([0-9]*\\) deletions(-)/\\2 \\3/p' | awk '{printf \"%6i\",($1 + $2)}'" | |
lines = %x[#{lines_cmd}] | |
# Replace the spaces with the lines changed. | |
commit = commit.gsub(" ", lines) if !lines.empty? | |
# Print out the new commit log. | |
puts commit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool script thanks 👍 I can't see colors tho 🤔