I use Git a lot and by default
git log is not very helpful. Git log has a lot of optional parameters, which can make the output much more useful.
Default Git Log
Improved Git Log
Using a combination of command line parameters, the git log output becomes beautiful and infinitely more useful.
git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
Features of Improved Git Log
- each commit uses only one line (allowing a much deeper look into project history)
- commit IDs are displayed in abbreviated format
- branching is visually indicated
- summary line of commit is displayed
- relative dates are used (e.g.
2 days agoinstead of an absolute date)
- name of committer is displayed
While the Improved Git Log is amazing, typing out the list of parameters each time would be ridiculous. Fortunately, Git allows us to create our own aliases. In this case, we’re going to create an alias to
git lg. By default if you run
git lg, you’ll get the message
git: ‘lg’ is not a git command. See ‘git –help’.
However, we can add the alias to our global configuration by running the following line:
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'
Now, every time we want the improved git log, we can type
How it Works
git config --global line above writes this new alias to your
.gitconfig file (which is found at
~/.gitconfig on a Mac).