Skip to main content

Python print() Function

When you start learning Python, one of the first things you need to learn is how to display information on the screen. For example, you might want to display: A welcome message. Your name and age. The result of a mathematical calculation. Student marks and results. Information generated by a Python program. Python provides a built-in function called print() for displaying information. The print() function is one of the simplest and most frequently used functions in Python. It helps programmers display information while testing programs, solving problems, and developing applications. In this article, we will learn how to use print() with practical examples and their outputs. 1. What Is the print() Function in Python? The print() function is a built-in Python function that displays information in the output area, usually the terminal or console. Let's look at a simple example. print("Hello, World!") Output: Hello, World! In this example, Python displays the text Hello,...

Understanding Git Commit History: git log, Commit Hashes, and Viewing Your Project Timeline

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 log is

  • How 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:

  • HEAD

  • Branches

  • 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 --oneline for 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

CommandPurpose
git logDisplay complete commit history
git log --onelineDisplay compact history
git log -5Show the latest five commits
git log --graph --onelineDisplay 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

Popular posts from this blog

Understanding Comments in Java: A Beginner’s Guide

When learning Java programming, one of the first concepts you’ll come across is comments . Comments may not affect how a program runs, but they play a crucial role in making code more understandable, readable, and maintainable. Let’s dive deeper into what comments are, why they’re important, and the different types of comments in Java. What are Comments in Java? A comment in Java is a piece of text written within a program that is ignored by the compiler . In other words, comments are notes for humans, not instructions for machines. They help developers explain the purpose of code, describe logic, or temporarily disable certain lines of code without deleting them. Why are Comments Important? 📌 Readability – Comments make code easier to understand for you and others. 📌 Maintenance – When you revisit your code after months, comments remind you what you were doing. 📌 Collaboration – In team projects, comments explain code to fellow developers. 📌 Debugging – You c...

Java Program to Check Voting Eligibility

In this program, we’ll take the user’s age as input and check whether the person is eligible to vote or not. In India, the minimum age required to vote is 18 years . 💻 Program Code // Java Program to Check Voting Eligibility import java.util.Scanner; public class VotingEligibility { public static void main(String[] args) { // Create Scanner object to take input from user Scanner sc = new Scanner(System.in); // Ask user to enter age System.out.print("Enter your age: "); int age = sc.nextInt(); // Check eligibility if (age >= 18) { System.out.println("You are eligible to vote."); } else { System.out.println("You are not eligible to vote yet."); System.out.println("You can vote after " + (18 - age) + " year(s)."); } sc.close(); // Close the scanner } } 🧠 Explanation import java.util.Scanner; → Imp...

Java Program to Calculate Total Marks and Average of Five Subjects

💡 Program Explanation In this program: The user will input marks of five subjects . The program will calculate the total marks and average . It will then display both results clearly. 🧑‍💻 Java Code: // Java Program to Calculate Total Marks and Average of Five Subjects import java.util.Scanner; // Importing Scanner class for user input public class TotalAndAverage { public static void main(String[] args) { // Creating Scanner object to take input from user Scanner sc = new Scanner(System.in); // Declaring variables for five subjects double subject1, subject2, subject3, subject4, subject5; // Taking marks input for each subject System.out.print("Enter marks of Subject 1: "); subject1 = sc.nextDouble(); System.out.print("Enter marks of Subject 2: "); subject2 = sc.nextDouble(); System.out.print("Enter marks of Subject 3: "); subject3 = sc.nextDo...