Git: View Commit History

This article is a short guide for using the git log command. Git Log is important when a user wants to view a history of all the commits that have been made for a particular project. The command can be used for a newly created project or a cloned project to have a view of all the commits that have been made.

ImageSource: https://blog.nakulrajput.com/git-log/

We can customize git log command depending on the user specific requirements. The various use cases are explained below.

Git Log Use Cases:

To have a detailed view of all the commits done on a project use the below command.

git log --all

Sample Output:

View Detailed Commit History

For a simple one line view of the commit history, use the below command:

git log --oneline

The output is as below:

View Simple Commit History

To show the details of a particular commit:

git show commit ID

The Output from the command is as below:

Show Details of a Particular Commit

The other commands that can be used to view details of our commits is:

git log -p

Sample output:

Show Details of all Commits

Suppose you have a long commit history and you only want to view the 10 most recent commits.

git log -10

For our example, we only made a few commits hence we showed output for the 2 most recent commits.

Show the Last 2 Recent Commits

To find all the commits made on a particular date or a particular period: For example, to view all commits that happened on the 22nd November 2020;

git log --after "2020-11-21" --before "2020-11-22"

Sample output.

To Check Commits for a Particular Period

To see commits that happened in the last 2 or 5 days, use the below command:

git log --after 5.days.ago

For our example, we viewed commits that happened in the last 1 day.

Commits in the last 1 day

To show all commits that were done before a specific day or period, use the below commands.

git log --before 2.day.ago
or
git log --before='2 days ago'

See sample output below.

Show all Commits Before 2 Days Ago

Suppose one wants to view commits done by a specific developer/author; For example, we want to view all the commits made by Maureen.

git log --author Maureen

Output:

Show Commits by a Particular Author/Developer

These are just a few of the basic git log commands. I have attached some links below for more information and additional commands to use for viewing any project’s commit history.

Important Links:

Git Log Documentation

More Git Log Commands

Git Log Guide

Other Git Commands Guides:

Git Stash Guide

Happy Reading!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s