This article looks at the best log aliases I use. Some I have found, some I have created and after reading you should be able to create your own easily.

Please feel free to submit your own in the comments below.

Add an alias

To add aliases, open your .gitconfig file and you will see an alias section:

1
2
[alias]
ac = !git add . && git commit -am

If you are on OSX, open a new command prompt and type:

1
open .gitconfig

To use the alias, simply type:

1
git aliasname

Log aliases

In no particular order:

1 - One liner with colors

Will log a list of commits, all on one line with customisable colours. Useful to know who has changed what on the repo recently.

1
l1 = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short

Source

2 - Graph one liner

Will log a list of commits with only the commit name and SHA. Useful to have a quick overview of the branches on the repo. I usually use the web UI for this, but this can be quicker if all you need is to refresh your memory.

1
l2 = log --graph --oneline --decorate --all

Source (first comment)

3 - Search commit name history

Will search previous commits for a specific term. Useful if you want to find a specific comment based on the comment.

1
l3 = !git log --oneline | grep

Use it like this

1
$ git log l3 JIRA # Will display all commits with 'JIRA' in the description

4 - Details about the last commit

Will show all the differences introduced in the last commit.

1
l4 = log -p -1

5 - Get commits for n days before today

Another one by myself. It makes use of functions and displays the list of commits made before X days ago.

1
2
3
l5 = "!f() { \
git log --after=\"$(date -j -v-$1d +%Y-%m-%d)\" --oneline; \
}; f"

Use it like this

1
$ git l5 15 # Get the commits made in the last 15 days

Summary

I hope you found these useful, I will add more as I go.

Here is the list so far:

1
2
3
4
5
6
7
l1 = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
l2 = log --graph --oneline --decorate --all
l3 = !git log --oneline | grep
l4 = log -p -1
l5 = "!f() { \
git log --after=\"$(date -j -v-$1d +%Y-%m-%d)\" --oneline; \
}; f"

Thanks for reading !