Make my git log look pretty and readable

Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

In order to always have a good overview of what’s going on in our repository, we use git log. However, the build-in git log output format is not really suitable for everyday usage. In this lesson we will create a dedicated git alias lg which will printout a nicely formatted git log list.

The example used in this video:

lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches

But there are more available on the web, just search for it :)

Instructor: [00:00] Let's execute one of the most used commands in Git and also one of the most important ones when you work in large Git repositories. It is the git log. The git log basically gives us an overview of what is happening on our current branch we are working on.

[00:14] Basically, it shows us the commit hash which allows us to eventually jump to certain commit messages. It shows us who committed this, when it has been committed, and also the commit message.

[00:26] However, as you can see the default command for git log is actually quite cumbersome and not easy to digest, especially if you have a lot of commit messages, this is hard to follow up and read.

[00:38] What we would like to have is a very condensed form, an abbreviated form of the git log messages. For that purpose, what we are going to create is a Git alias which allows us to write something like git lg, which would then print out our condensed and nice formatted messages.

[00:55] You can define such Git aliases in the .gitconfig file, which should actually reside in the root folder of your user. If the file doesn't exist, simply create one with Touch and then open it up with your preferred editor.

[01:07] Let's jump to the file. If you already had a git config file, you might have already all the configurations inside here which Git added for you automatically. Otherwise, I said simply create a new file, search for a section that's called "Alias." Otherwise, create one just as I do. Then, basically go to a new line and create an lg alias.

[01:27] Whenever we then execute git lg, it will execute the comment here. What we want to do is to execute the git log. We want to have also a coloring, also a graph in case of multiple branches, we want to have some kind of graph that shows us how these branches are being merged and when they have been created.

[01:47] We also add in here the pretty format, which will do some formatting for us. I simply paste in here a formatting string. Simply copy and paste this string here into your own git config. Also, pass in the abbreviated comment format, then save everything.

[02:03] Back in our console here, let's now try our command and do a git lg. Now, we can see we get this nicely formatted log messages. We have to shorten git commit hash codes here in front. We see where our hat currently points. We see the last branch where it currently are. We see the commit messages, when it has been committed, and by whom it has been committed.

Roberto Zaniboni
Roberto Zaniboni
~ 5 years ago

thanks, very useful.

Juri Strumpflohner
Juri Strumpflohnerinstructor
~ 5 years ago

Hey @Roberto, thx 😊. Glad you liked it and I was able to help 🙂

Kevin E Rad
Kevin E Rad
~ 5 years ago

Great, you can also use tig tool (brew install tig) :)

Oscar Saraza
Oscar Saraza
~ 5 years ago

Hi, I can't make the .gitconfig works as you showed. The command git lggive me an error: "git: 'lg' is not a git command." I created the file on the project's root folder and added the alias. There's any additional step or requirement to this file to work?

Juri Strumpflohner
Juri Strumpflohnerinstructor
~ 5 years ago

@Oscar make sure it's on the "root" folder of your User not the project itself. On unix systems it is ~/.

Jexxie
Jexxie
~ 5 years ago

Why I type 'git lg' will show a new panel and should hit 'q' to exit while you just show the message in the same panel?

Jexxie
Jexxie
~ 5 years ago

Why I type 'git lg' will show a new panel and should hit 'q' to exit while you just show the message in the same panel?

Juri Strumpflohner
Juri Strumpflohnerinstructor
~ 5 years ago

@Jexxie I'm having the same "issue" on my work Mac while it works as I've shown in my own Mac 🤔. Noticed that weird behavior as well, but didn't investigate yet. I'll let you know if I find out

Markdown supported.
Become a member to join the discussionEnroll Today