Home Coding & Scripting Exploring Commit History with git log

Exploring Commit History with git log

159
0

After understanding how Git tracks changes through the working directory, staging area, and repository, the next important skill is learning how to explore our project’s history.

Every time we run git commit, Git creates a snapshot of our project. But how do we view those snapshots? How do we see what changed over time?

This is where the git log command becomes powerful.

In this guide, we will explore how to read, understand, and navigate commit history using git log.


🧩 Prerequisites

Before exploring commit history, make sure:

  • We understand the Git workflow stages (Working Directory → Staging → Repository)
  • Git is installed and configured properly
  • We have already created a repository
  • We have made at least one or two commits

If you have not yet completed those steps, please refer to: Git Repository Structure and Workflow Stages


📜 What Is git log?

The git log command displays the history of commits in our repository.

Each commit represents a saved snapshot of our project at a specific point in time.

To view commit history, simply run:

git log

Git will display:

  • Commit ID (SHA hash)
  • Author name
  • Author email
  • Date and time
  • Commit message

🧠 Understanding a Commit Entry

When we run git log, the output looks something like this:

commit a1b2c3d4e5f67890abcdef1234567890abcdef12
Author: Your Name <your@email.com>
Date: Mon Nov 18 10:15:30 2025 Add newfile.txt

Let’s understand each part:

🔹 Commit ID

A long unique hash that identifies the commit.
This is generated using cryptographic hashing.

Every commit has a unique ID.

🔹 Author

The person who created the commit.

🔹 Date

The exact time the snapshot was saved.

🔹 Commit Message

A short description explaining what was changed.

This is why writing meaningful commit messages is important.


🧪 Exercise 1: Viewing Your Commit History

If we already have a repository:

1️⃣ Navigate to our project folder
2️⃣ Run:

git log

If we only have one commit, we will see one entry.

If we have multiple commits, we will see a list — newest first.

Notice how Git shows commits in reverse chronological order.


➕ Creating More Commits for Practice

To better understand commit history, let’s create additional commits.

Step 1: Modify an Existing File

Open newfile.txt and add:

This is the second version of the file.

Stage and commit:

git add newfile.txt
git commit -m "Update newfile.txt with second version"

Step 2: Create Another File

Create anotherfile.txt with:

This is another file.

Stage and commit:

git add anotherfile.txt
git commit -m "Add anotherfile.txt"

🧪 Exercise 2: View Updated Commit History

Now run:

git log

We should now see three commits.

Observe:

  • Each commit has a unique ID
  • Each has a message
  • Each has a timestamp
  • The latest commit appears at the top

🔎 Simplifying the Output with --oneline

The default git log output can look long.

To make it compact, use:

git log --oneline

This shows:

  • Shortened commit ID
  • Commit message

Example:

a1b2c3d Add anotherfile.txt
9f8e7d6 Update newfile.txt with second version
3e4f5a1 Add newfile.txt

This view is extremely useful when quickly scanning history.


🧪 Exercise 3: Try Compact View

Run:

git log --oneline

Notice how much cleaner the output becomes.

This format is commonly used in daily development.


🔄 Understanding Commit Order

Commits are connected in a chain.

Each commit points to the previous one.

The most recent commit is referred to as:

HEAD

HEAD always points to the latest commit in your current branch.

You can verify your current branch using:

git branch

(We will explore branches in detail in a later post.)


🧭 Viewing a Limited Number of Commits

If our project grows large, the log can become long.

To limit the output:

git log -n 2

This shows only the last 2 commits.


🧪 Exercise 4: Limit Commit Display

Run:

git log -n 2

Observe how Git only shows the most recent two commits.

This helps when working in large repositories.


📌 Why Exploring History Matters

Understanding git log allows us to:

  • Track when changes were made
  • See who made changes
  • Review commit messages
  • Identify specific commits using IDs
  • Navigate project evolution

Without git log, our repository would feel like a black box.

With it, our project history becomes transparent.


🎨 Real-Life Analogy

Think of our repository like a diary.

Each commit is an entry.

git log is how we flip through the pages and review our past entries.

It shows:

  • When we wrote something
  • What we wrote
  • In what order

🧠 Putting It All Together

So far, we have learned:

  • Every commit is a snapshot
  • Git stores commit history in the repository
  • git log displays those snapshots
  • We can simplify output with --oneline
  • We can limit results with -n

These tools help us understand the evolution of our project.


🎯 Final Thoughts

Exploring commit history is a crucial skill in Git.

Before learning branching, merging, or undoing changes, you must feel comfortable reading commit history.

git log gives us visibility into:

  • Our work
  • Our progress
  • Our project’s timeline

In the next post, we will explore how to compare changes between commits using git diff, which helps us see exactly what changed inside our files.

Now that we can create commits and explore them, our Git workflow is becoming stronger and more confident.

Previous articleHow Git Internally Tracks Changes (Snapshots, Index, and Hashing Explained)
Next articleUndoing Changes with git restore
Heartin Kanikathottu
As a seasoned Cloud and Security Architect, I’ve led transformative initiatives in key roles, including Vice President at Morgan Stanley, Principal Architect at Societe Generale, and Tech Lead & Cloud Security Architect at VMware, among others. I’m also an internationally published author with multiple books available on platforms like Amazon and O'Reilly. Notably, one of my books was recognized as the 8th best cloud computing book of all time in 2020, reflecting the impact of my contributions to the field. With over 15 professional certifications from providers such as Microsoft (Azure), Amazon (AWS), Oracle (Java), Pivotal (Spring), and IBM, I bring a wealth of expertise to my work. Academically, I hold dual Master’s degrees in Cloud Computing and Data Analytics. I’m passionate about sharing knowledge and mentoring others, which is why I actively speak at global technical forums such as Tech Opportunities Fest at Platform Calgary, Google's Kubernetes Meetup, Java User Group, Elasticsearch Meetup, and the Agile India Conference.

LEAVE A REPLY

Please enter your comment!
Please enter your name here