Logging

Viewing The Commit History

To view the commit history, run

$ git log

To see the differences introduced in each commit and limit the entries to 2

$ git log -p -2

To see some stats for each commit

$ git log --stat

To see more readable options of the commits

$ git log --pretty=oneline

$ git log --pretty=short

$ git log --pretty=full

$ git log --pretty=fuller

You can specify the log format with the command

$ git log --pretty=format:"_OPTIONS_INSIDE_HERE_"

The available options can be found in the following table

ValueOption Description
%HCommit hash
%hAbbreviated commit hash
%TTree hash
%tAbbreviated tree hash
%PParent hashes
%pAbbreviated parent hashes
%anAuthor name
%aeAuthor email
%adAuthor date (format respects the --date=option)
%arAuthor date, relative
%cnCommitter name
%ceCommitter email
%cdCommitter date
%crCommitter date, relative
%sSubject

To print a graph with the branch and merge history

$ git log --graph

Limiting log output with --since or --until for e.g. weeks/years/days/minutes or specific dates "2008-01-15" or "2 years 1 day 3 minutes ago". The --author filter is also available

$ git log --since=2.weeks

To find the last commit that added or removed a reference to a specific function

$ git log -S _FUNCTION_NAME_

To list all your branches

$ git branch -a

A nice example of a graph is the following

$ git log --pretty=format:"%h %s" --graph