Simplifying Git Commit Graph

On January 2, 2012, in Git, by Anuj Gakhar

Git is my favorite source control tool and I try to use it in pretty much all the projects I work on. Yesterday, I watched the Advanced Git Screencast from PeepCode and like all other screencasts from PeepCode, I liked it a lot and ended up with a much better understanding of Git branching/merging/reflog in general and I am glad I took the time to watch the screencast. I won’t be going into detail of everything that was covered in the screencast but one thing that I think was quite useful was the Git Commit graph. I have been using “git log” command for quite a while and I know there are a few variations you can do to prettify the output, but the git log output used in this screencast was particularly very useful and something I could get used to very easily, I think.

To give you an idea of what I am talking about, here is how the git commit graph of Twitter’s Bootstrap library looks like using the command from the screencast:-

What I like the most about the above output is that, it tells me exactly where the project stands as of now. It tells me where the current HEAD is, the latest commit, the branching/merging going on, author information and the commit SHA. All packed in one line and in a nice graph.

The git command used to get this output is :-

[xml]

git log –graph –pretty=format’:%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset’

[/xml]

Ofcourse, you don’t have to type that command everytime you want to run it. You can add the following alias to your .gitconfig file

[xml]
[alias]
# Log display, with train tracks.
l = log –graph –pretty=format’:%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset’
[/xml]

And then you can simple type “git l” to achieve the same result. Pretty neat, huh!

In the peepcode screencast, the author talks to Ben Hoskings, who explains the inner workings of Git Branching and merging. There are some other useful Git scripts on Ben’s dot-files repo as well and you should check them out, particularly the git aliases.

Tagged with:  

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2011 Anuj Gakhar
%d bloggers like this: