Every software project has a story.
The first commit creates the project structure. Later commits add new features, fix bugs, improve performance, update documentation, and refactor code.
Git records this entire journey.
But how do you view that history?
The answer is the git log command.
The git log command allows you to view every commit that has been made in a repository. It displays who made each commit, when it was created, the commit message, and the unique Commit ID.
Whether you are working alone or with a team, git log is one of the most useful Git commands because it helps you understand how a project has evolved over time.
In this article, you will learn:
What
git logisHow to view commit history
What information each log entry contains
Understanding Commit Hashes
Different ways to display Git history
Short and compact logs
Viewing logs graphically
Filtering commit history
Best practices for reading Git logs
By the end of this article, you will know how to inspect the complete timeline of any Git repository.
What is the git log Command?
The git log command displays the commit history of a Git repository.
Basic syntax:
git log
When executed, Git displays commits from the newest to the oldest.
Each commit represents a snapshot of your project.
Why is git log Important?
Imagine you return to a project after six months.
You may ask:
What changes were made?
Who made those changes?
When were they made?
Which commit added a feature?
Which commit fixed a bug?
Instead of guessing, you simply run:
git log
Git provides the complete history.
Creating Sample History
Suppose you create the following commits.
git commit -m "Create project structure"
git commit -m "Add login feature"
git commit -m "Add student dashboard"
git commit -m "Fix password validation"
Now run:
git log
Git may display something similar to:
commit d4f7a3d2e0c64d31f92c17b1d8f1e5b67d1a9f1c
Author: Rahul Sharma <rahul@example.com>
Date: Wed Jul 15 11:20:35 2026 +0530
Fix password validation
commit a3f72b18e91c457c2c419d5a7a4821d729f01345
Author: Rahul Sharma <rahul@example.com>
Date: Wed Jul 15 10:45:20 2026 +0530
Add student dashboard
commit 7d43ab9124d78b12345bcde98ab45d1234567890
Author: Rahul Sharma <rahul@example.com>
Date: Wed Jul 15 10:10:11 2026 +0530
Add login feature
commit 92bd0d99876a4b1d89fe671245c8d22345f87654
Author: Rahul Sharma <rahul@example.com>
Date: Wed Jul 15 09:30:02 2026 +0530
Create project structure
This is your project's timeline.
Understanding a Log Entry
Each commit displayed by git log contains several pieces of information.
Example:
commit d4f7a3d2e0c64d31f92c17b1d8f1e5b67d1a9f1c
Author: Rahul Sharma <rahul@example.com>
Date: Wed Jul 15 11:20:35 2026 +0530
Fix password validation
Let us understand each part.
Commit Hash
The first line begins with:
commit
followed by a long string:
d4f7a3d2e0c64d31f92c17b1d8f1e5b67d1a9f1c
This is called the Commit Hash.
It is a unique identifier generated by Git.
No two commits have the same hash.
Think of it as the commit's fingerprint.
Why Does Git Use Commit Hashes?
Suppose your repository contains:
Add login feature
Add login feature
Add login feature
Three commits have identical messages.
Git cannot identify them using the message alone.
Instead, Git uses unique commit hashes.
Example:
d4f7a3d → Add login feature
81ab62e → Add login feature
ab72de1 → Add login feature
Each hash points to one specific commit.
Author Information
Git also displays:
Author:
Example:
Author: Rahul Sharma <rahul@example.com>
This tells you who created the commit.
Git obtains this information from:
git config user.name
and
git config user.email
This information is especially useful in team projects.
Date
Example:
Date: Wed Jul 15 11:20:35 2026 +0530
Git records the exact date and time when the commit was created.
This helps developers understand the project's development timeline.
Commit Message
The final section is the commit message.
Example:
Fix password validation
This explains the purpose of the commit.
A meaningful commit message makes the project history easy to understand.
Why Does Git Show the Latest Commit First?
Git displays commits in reverse chronological order.
Example:
Newest Commit
│
▼
Older Commit
│
▼
Oldest Commit
This allows developers to immediately see the latest project changes.
The git log --oneline Command
The default log can become lengthy.
Git provides a compact version:
git log --oneline
Example output:
d4f7a3d Fix password validation
a3f72b1 Add student dashboard
7d43ab9 Add login feature
92bd0d9 Create project structure
Each commit is displayed on a single line.
This is one of the most commonly used forms of git log.
Understanding the Short Commit Hash
Notice:
d4f7a3d
This is a shortened version of the complete hash.
Git automatically shortens hashes while keeping them unique within the repository.
The full hash may contain 40 hexadecimal characters.
Most Git commands accept the shorter version as long as it uniquely identifies the commit.
Viewing the Last Few Commits
Sometimes you only want to view recent commits.
Example:
git log -3
Output:
Commit 1
Commit 2
Commit 3
Only the three most recent commits are displayed.
Similarly:
git log -5
shows the latest five commits.
Viewing Commits Graphically
Git can display commit history as a graph.
Run:
git log --graph --oneline
Example:
* d4f7a3d Fix password validation
* a3f72b1 Add student dashboard
* 7d43ab9 Add login feature
* 92bd0d9 Create project structure
This becomes especially useful when working with branches and merges.
Viewing Full Details
If you want complete information, simply use:
git log
This displays:
Commit Hash
Author
Date
Commit Message
It is the most detailed form of the command.
Viewing Commit History with Decorations
Run:
git log --oneline --decorate
Example:
d4f7a3d (HEAD -> main) Fix password validation
a3f72b1 Add student dashboard
7d43ab9 Add login feature
The decoration tells you where:
HEADBranches
Tags
are currently pointing.
We will study these concepts later.
Filtering Commits by Author
Suppose multiple developers work on the same repository.
You can view commits by a specific author.
Example:
git log --author="Rahul"
Git displays only commits created by Rahul.
Searching Commit Messages
Suppose you want to find commits related to "login".
Run:
git log --grep="login"
Git searches commit messages containing the word "login".
Example:
Add login feature
Fix login validation
Improve login page
This is extremely useful in large repositories.
Viewing History for a Specific File
Suppose you only want to view commits involving:
Main.java
Run:
git log Main.java
Git displays only commits that affected Main.java.
This helps track the history of an individual file.
Viewing One Commit
If you know a Commit Hash:
d4f7a3d
You can inspect it using:
git show d4f7a3d
Git displays:
Commit information
Commit message
Code changes introduced by that commit
We will explore git show in detail in a later article.
Real-World Example
Suppose you are developing an E-Commerce application.
Your commits look like this:
Create project structure
Add user registration
Add login system
Add shopping cart
Fix payment bug
Improve checkout page
Update README
Six months later, a bug appears in the shopping cart.
Run:
git log --grep="shopping"
Git immediately finds the commit that introduced the shopping cart.
Without Git, locating that change would be much more difficult.
Understanding the Project Timeline
Git history is similar to a timeline.
Create Project
│
▼
Add Login
│
▼
Add Dashboard
│
▼
Fix Login Bug
│
▼
Improve Performance
│
▼
Release Version 1.0
Every commit becomes part of this timeline.
Common Beginner Mistakes
Mistake 1
Ignoring commit messages.
Good commit messages make git log meaningful.
Mistake 2
Creating very large commits.
Small commits create a cleaner and more understandable history.
Mistake 3
Thinking Commit Hashes can repeat.
Each commit hash is unique.
Mistake 4
Only using the default git log.
Learn useful variations such as:
git log --oneline
and
git log --graph --oneline
Best Practices
Write meaningful commit messages.
Use
git log --onelinefor everyday work.Review commit history regularly.
Search commit history instead of guessing when a change was made.
Create logical commits so the timeline remains easy to understand.
Useful git log Commands
| Command | Purpose |
|---|---|
git log | Display complete commit history |
git log --oneline | Display compact history |
git log -5 | Show the latest five commits |
git log --graph --oneline | Display commit graph |
git log --author="Name" | Show commits by a specific author |
git log --grep="text" | Search commit messages |
git log <filename> | Show history of a specific file |
git show <commit-hash> | Display details of one commit |
Summary
The git log command is your window into a project's history. It displays every commit, along with its unique hash, author, date, and message.
Whether you need to review recent work, investigate a bug, search for a specific feature, or understand how a project has evolved, git log provides the tools to navigate Git history efficiently.
Learning to read commit history is an essential skill for every developer, especially when collaborating on large projects.
Comments
Post a Comment