A better git log
So, are you tired of this old and bored git log screen?
How about this one, instead?
It's simple. Just type in:
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
I guess that's a bit too long, eh? Let's just make an alias. Copy and paste the line below on your terminal:
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
And every time you need to see your log, just type in
git lg
Or, if you want to see the lines that changed
git lg -p
Hope you like it :)
PS: It seems that there's no way to view larger images, so I've linked bigger versions of them on the tip. Just click the image. Thanks to @basus(http://www.twitter.com/basus) for the note
Update: As some people were reporting, the git lg -p
command wasn't working. As pointed out by the user universal_property at reddit, removing the -- at the end made it work.
Update 2 (by @cervedin): I would suggest changing %cr to %ar as commit dates change when rebasing
Written by Filipe Kiss
Related protips
50 Responses
This doesn't work for individual files
@askjuise Thank. I've fixed. :)
You guys can try this one :
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"
this will:
-one commit per line
-show graph of commits
-abbreviated commit IDs
-dates relative to now
-show commit references (like git log --decorate
)
-lots of colour
-show author of the commit
Cool Filipe! Thanks!
Great Filipe! Thanks :)
Very nice, thanks man
thats amazing. thanks!
Thanks man! For copy-pasting change-logs, here's an ascii friendly version:
git log --graph --pretty=format:'%h -%d %s (%cr) <%an>' --abbrev-commit
...and the alias:
git config --global alias.lg-ascii "log --graph --pretty=format:'%h -%d %s (%cr) <%an>' --abbrev-commit"
[alias]
lg = !tig
google "tig" for more info
This is great, thanks!
Rather than a git alias, I opted for a bash alias by adding this line to my .bash_profile
:
alias gitlog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Now I have gitlog
and gitlog -p
.
Thanks again!
git log | tig
Try this
git log --oneline --abbrev-commit --all --graph --decorate --color
It will give you one line commits, plus branching.
FYI, %h is for abbreviated commit hash, making --abbrev-commit redundant.
Call me old fashioned. I use the alias glo
mapped to
git log --decorate --oneline --graph
and that works well for me.
Or, if I'm feeling like I need something a bit different, glg
, which is mapped to
git log --decorate --graph --abbrev-commit --date=relative
https://github.com/kevinSuttle/dotfiles/blob/master/git/aliases.zsh#L11
This is great! Thanks :D
I like this one, that shows the branch graph on the left:
history = log --graph --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'
stash-list = stash list --pretty=format:'%Cblue%gd%Cred: %C(yellow)%s'q
@dshafik Mine also shows the graph :) It just happened to be a flat-line for the screenshots I've chose :P
Love it!
scm_breeze on github does something similar automatically plus a bunch of other nice aliases
There is no need for --abbrev-commit
.
Thanks for the tip though, I trimmed mine down to:
git log --format='%Cred%h%Creset %s %Cgreen(%cr) %C(blue)<%an>%Creset%C(yellow)%d%Creset' --no-merges
This is great, thanks for sharing !
Great stuff.
I keep it simple with
git log --oneline --decorate --graph
This shows each commit on one line, decorates each line with any information about branches and repos and displays a graph where commits have branched or merged.
If you want to really personalise you git log with specific colours, here is an article to explain the syntax of all that in detail:
http://blog.jr0cket.co.uk/2013/06/designing-your-own-commit-graph-with-git.html
Thanks
John
In my gists NOW!
Eu te amo! haha
I'd prefer to set the default to --graph --decorate, rather than cook up a new alias. :/
Nice! Any tips on porting this to Fish? I'm quite new to the command line stuff, and I can't find any reference to %C, string interpolation or command line styling for Fish shell. /lost
update: Okay, so the reason why I was getting an error was, I was putting white space between the '='. My bad! Carry along.
The git plugin of oh-my-zsh comes with tons of aliases, including log aliases.
- alias glgg='git log --graph --max-count=10'
- alias glgga='git log --graph --decorate --all'
- alias glo='git log --oneline --decorate --color'
- alias glog='git log --oneline --decorate --color --graph'
Just install tig, a much much better command line tool for git
Pretty sweet!, now I can read the git log so much easier
As of Git 1.8.3 (May 24, 2013), you can now have (automatic) more comprehensive and useful colors on commits, branches and tags using %C(auto)
:
git log --graph --pretty=format:'%C(auto)%h -%d %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Cool ;)
Take it.
Thank you Filipe.
awesome, Boy!
Wow, cool. I guess I'll look at my log now than on Bitbucket or Github. Thanks for sharing.
nice!
Great..!! thank you for sharing..
Thanks, i'll try it
Awesome, really useful! :)
Fantastic
Where this command saved? I can't see it in my zshrc file.
Thank you for this :)
Thanks, this is great!
Amigo, muchas gracias, es un excelente aporte.
Using this as base I change it a little bit.
git config --global alias.lg "log --color --graph --pretty=format:'%C(#dc322f)%h%C(#b58900)%d %C(#eee8d5)%s %C(#dc322f)| %C(#586f75)%cr %C(#dc322f)| %C(#586e75)%an%Creset' --abbrev-commit"
[ Screenshot ]
https://i.imgur.com/4i8cTy2.png
very nice, I would suggest changing %cr to %ar as commit dates change when rebasing
ah... great config. really love it
Buddy, well done.
One more interesting variant:
git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
I also want to add, you can write the git log output stream to a file and see an HTML report about your repository. There are many open-source solutions for this. For example https://github.com/bakhirev/assayo