DEV Community

Arturo Linares
Arturo Linares

Posted on • Originally published at arturo.linar.es on

Git log filtering and how to show a better history tree

Some useful commands to find commits using Git:

Filter by content

Filter by the contents of a commit. Think of it as if you do a git log -p (shows the diff of each commit) and then you search the output.

git log -S var_dump

Filter by commit message

git log --grep "FRB-666"

Filter by author

git log --author "Arturo"

You can use emails and several values:

git log --author "outlook.com|hotmail.com"

Filter by date

Conveniently accepts --before and --after

git log --before "2017-06-11"

Git log format

I've found that git log is powerful, but sometimes difficult to read. Normally I use this git alias to show a nice tree in the console:

$ git config --global alias.lg
log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)%Creset' --abbrev-commit

This will show a tree like this when you type git lg

Terminal with git log tree

Top comments (1)

Collapse
 
jmcp profile image
James McPherson

I'm stealing that alias :-) Very useful, thankyou