Git Cheatsheet - Logging
- Anuja Dalal
- Dec 6, 2023
- 4 min read
Updated: Apr 21, 2025

The "git log" is a very useful command to log the commit history of the project. Please note it is different from "git status" which gives information respective to working branches and the state of file edits in the working directory while "git log" provides detailed information about commits, author, commit message, checksum, Head pointer etc.
In its simplest form -
$ git log
commit 641306cdcdf2cf6ec4f8604d4bb0180fac8a796a (HEAD -> master, origin/master, origin/HEAD)
Author: Anuja Dalal <anuja@example.com>
Date: Mon Aug 22 17:54:15 2022 -0600
The first blog
commit g76cc02cd7a537f720b7e2e7543e4e8a5873f072
Author: Amol Paradkar <amol@example.com>
Date: Mon Aug 20 23:36:06 2022 +0000
Initial commit
$The above output tells where the HEAD is pointing to i.e. master branch is a checked out branch. It shows details about the commit author, date, author email, and commit message. It will give the list of all the commits made to the checked-out branch.
If you pass --abbrev-commit to the git log command, the output will use shorter values of SHA-1 hash. Generally, it displays seven characters but makes them longer if necessary to keep the SHA-1 unambiguous.
$ git log --abbrev-commit
commit 641306c (HEAD -> master, origin/master, origin/HEAD)
Author: Anuja Dalal <anuja@example.com>
Date: Mon Aug 22 17:54:15 2022 -0600
The first blog
commit g76cc02
Author: Amol Paradkar <amol@example.com>
Date: Mon Aug 20 23:36:06 2022 +0000
Initial commitTo see the commit history of the branch that is not currently checked out, specify the branch name "git log <branch-name>".
# git log <branch-name>
$ git branch
develop
* feature/blog
feature/services
master
$ git log master
commit 641306cdcdf2cf6ec4f8604d4bb0180fac8a796a (master)
Author: Anuja Dalal <anuja@example.com>
Date: Mon Aug 22 17:54:15 2022 -0600
The first blog
commit g76cc02cd7a537f720b7e2e7543e4e8a5873f072
Author: Amol Paradkar <amol@example.com>
Date: Mon Aug 20 23:36:06 2022 +0000
Initial commit
$To customize the log output format use option --pretty=<value>. The <value> could be oneline, short, full, fuller etc. The oneline value for this option prints each commit on a single line, which is useful if you’re looking at a lot of commits.
$ git log --pretty=oneline
641306c (HEAD -> master, origin/master, origin/HEAD) The first blog
g76cc02 Initial commit
$Value oneline can be used directly as an option and output will be the same.
$ git log --onelineThe other pretty values are -
$ git log --pretty=short
$ git log --pretty=medium
$ git log --pretty=full
$ git log --pretty=fuller
$ git log --pretty=email
$ git log --pretty=rawOption pretty with formats, which allows you to specify your own output format. This is especially useful when you’re generating output for machine parsing — because you specify the format explicitly, you know it won’t change with updates to Git.
$ git log --pretty=format:<format-string>
$ git log --pretty=format:"%h - %an, %ar : %s"
$ git log --pretty=format:"Hello I am %an, my commit is %h"
Some useful placeholders for format-string -
%H commit hash
%h abbreviated commit hash
%an author's name
%ae author email
%ad author date (format respects --date= option)
%aD author date, RFC2822 style
%ar author date, relative
%at author date, UNIX timestamp
%ai author date, ISO 8601-like format
%aI author date, strict ISO 8601 format
%as author date, short format (YYYY-MM-DD)
%s subjectIt is possible to limit the log to a specific period.
# To see commits during the last 2 weeks
$ git log --since=2.weeks --oneline
dcae782 (HEAD -> master, origin/master) Initial project setup
$
$ git log --after=2.weeks --oneline
dcae782 (HEAD -> master, origin/master) Initial project setup
$
$ git log --since="2 weeks ago"
dcae782 (HEAD -> master, origin/master) Initial project setup
$More -
# To list commits older than a specific date
$ git log --until=14/10/2020
$ git log --before=2022-10-20
$ git log --before="yesterday"
# To list the commits made between a date range
$ git log --after="2022-06-1" --before="2022-06-10"To find the commits that added or modified a reference to a specific string.
$ git log -S function_nameAnother popular option is -L which displays lines of code containing the string you specified along with information about the commit. Ex: to see the function changed in a certain file you can use the following command.
$ git log -L :function_name:somefile.jsThe -L option can use regex to support complex searches.
To limit the log output to commits that introduced a change to some specific files. Use "--" to specify multiple file names.
$ git log -- path/to/file1 -- path/to/file2The log can be filtered by message or author.
# Display commits made with message feature-100
$ git log --grep="feature-100"
# This is different from 'git grep "feature-100" ' which finds text in the code and displays the line from the code
# All commits made by Jill Joe
$ git log --author="Jill Joe"
# or
$ git log --committer="Jill Joe"To see the text-based graphical output of the log use option --graph.
$ git log --oneline --graph
* c2b9e (HEAD, master) Make other changes
| * 87ab2 (develop) Make a change
|/
* f30ab Add feature-1 - blog service
* c3ac2 Add Readme
* a3ca9 Initial commit
$This means commit f30ab is the parent commit of 2 commits. One is c2b9e from the master branch and the other is 87ab2 from develop branch. This graphical representation also tells that the current branch is the master branch.
There are many other options available with the "git log" command. It is a powerful tool for searching commit history. Listed here are a few of them commonly used. Feel free to explore this command and tell us which version you like best or what complicated version has helped you make your searches easier.



Comments