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.
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
For a simple one line view of the commit history, use the below command:
git log --oneline
The output is as below:
To show the details of a particular commit:
git show commit ID
The Output from the command is as below:
The other commands that can be used to view details of our commits is:
git log -p
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.
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"
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.
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.
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
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.
Other Git Commands Guides: