What is the git log command?

Git is an open-source version control system used for tracking changes in any project. It allows projects to be managed by multiple entities simultaneously. When working together, it can be important to have a log of changes made in the project.

The git log command is used to display the history of commits in any project. In this Answer, we will explore using and interpreting the git log command.

Output of the default git log command
Output of the default git log command

By default, the git log command displays these four things: commit message, date, author, and SHA of the commit made. However, Git provides us with flags to explore the command.

Implementation

Now that we have understood the log command, we will see a practical demonstration.

Installing git

  1. Before using git, we must ensure the version control system is installed in our terminal. We can install this with the following command:

apt-get install -y git
  1. We can ensure installation with the command below:

git --version

Cloning the repository

After installing git, we need a project setup to illustrate the command by performing the following steps:

  1. We receive the repository link from GitHub.

  2. Then, we clone the repository. We can clone any repository.

git clone <repository link>
  1. Next, we enter the cloned directory using the cd command.

cd <cloned directory name>

Using the git log command

Now, our terminal is all set up for using this command. We execute the git log command inside the cloned directory, as shown below:

git log

The git log command shows an output similar to the code snippet attached below:

commit b323b8b9805c47391b591m331b88fd4ba9d20830 (HEAD -> main, origin/main, origin/HEAD)
Author: Educative <Educative.io>
Date: Thu Dec 29 14:48:39 2022 +0500
Added NewFile
commit 1fe39fc275m2761hz2a67dc29820e104b6fb3e6bc
Author: Educative <Educative.io>
Date: Thu Dec 29 14:47:27 2022 +0500
Delete Old_File.docx
commit 1385274hc911b98cde80d3f583779b90c11a96b
Author: Educative <Educative.io>
Date: Thu Dec 29 14:47:07 2022 +0500
Update README.md
Output of the git log command

We are now familiar with the default git log command and its output. Here are some flags that can help us obtain relevant information:

  • git log --oneline: This flag lets the user ignore the author and date fields. Also, because this flag shows one-liners for each commit, it shows the first seven characters of SHA and leaves the rest.

  • git log --stat: This flag displays the files modified and the number of changed lines in each commit.

  • git log --graph: This flag lets the user view the logs as a graph. This helps in getting a better overview of the historical changes.

We can also use a hybrid of these flags together. For example, git log --graph --oneline can show us a graph of one-liners. Help yourself with exploring with these flags in the terminal below. Here’s a summary of the commands for reference:

apt-get install -y git
git --version
git clone <link to repository>
cd <cloned directory name>
# default log command
git log
# log command with flags
git log --graph
git log --oneline
Summary of commands

Terminal 1
Terminal
Loading...

Note: Replace <link to repository> with your own git repository link and the <cloned directory name> with your cloned directory name.

Conclusion

In summary, the git log command provides valuable insights into project history. In this Answer, we covered three flags: --oneline, --graph, and --stat. To explore more options, review the git-log documentation for additional flags and functionalities.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved