Skip to content

Reading Commit History with git log

Every commit records a checkpoint in the project’s history.

After creating several commits, we need a way to answer questions such as:

  • What is the latest commit?
  • What commits were created before it?
  • Who created each commit?
  • When was it created?
  • Why was it created?
  • What is its commit ID?

We use:

Terminal window
git log

to read the commit history that is reachable from our current position.

This command is read-only. It displays history but does not modify files, commits, or the repository.

Suppose we created the following commits in this order:

Initial commit
Create auth module scaffold
Add login form validation
Fix login crash on empty password

Running:

Terminal window
git log

may display:

commit a3f8c21b9e04d7f1...
Author: Omar <omar@sim.com>
Date: Sun Jul 26 21:00:00 2026
Fix login crash on empty password
commit 91bc044e...
Author: Omar <omar@sim.com>
Date: Sun Jul 26 18:12:00 2026
Add login form validation
commit 4e21aa0f...
Author: Omar <omar@sim.com>
Date: Sun Jul 26 17:45:00 2026
Create auth module scaffold
commit c0ffe01a...
Author: Omar <omar@sim.com>
Date: Sun Jul 26 16:30:00 2026
Initial commit

git log displays commits from newest to oldest.

Therefore, the first commit block is normally the latest commit at our current position.

In this example:

Fix login crash on empty password

is the newest commit, while:

Initial commit

is the oldest commit shown.

A beginner-friendly rule is:

Read git log from top to bottom: newest first, older commits below.

HEAD represents our current position in the repository history.

In a normal simple case, it points to the latest commit on the currently checked-out branch.

Therefore, the first entry shown by git log is normally the commit referenced by HEAD.

Every block in the output describes one commit.

commit a3f8c21b9e04d7f1...

This is the commit’s full identifier, commonly called the commit hash or commit ID.

It allows Git and developers to identify a specific checkpoint in the project history.

Different commits receive different IDs because their stored information is different.

Author: Omar <omar@sim.com>

This shows the name and email recorded as the author of the commit.

These values normally come from the Git author configuration that was explained in the First-Time Configuration lesson.

Date: Sun Jul 26 21:00:00 2026

This shows when the commit was created.

Fix login crash on empty password

The commit message explains the purpose of the checkpoint.

A useful message helps us understand why the change was saved without opening every file.

In a simple linear history, each commit points to the commit that came before it, called its parent.

Git begins at HEAD and follows these parent links backward through history.

  1. HEAD Newest

    Fix login crash on empty password

    git log starts reading the history from here.

  2. Parent

    Add login form validation

  3. Parent

    Create auth module scaffold

  4. Oldest commit

    Initial commit

    Has no parent, because no commit existed before it.

This is why git log can display the project timeline from the newest checkpoint back to older checkpoints.

When the repository has many commits, Git may open the output inside a pager such as less.

The bottom of the terminal may display a colon:

:

To exit and return to the shell, press:

q

The normal git log output contains detailed information for every commit.

For a shorter view, use:

Terminal window
git log --oneline

Example:

a3f8c21 Fix login crash on empty password
91bc044 Add login form validation
4e21aa0 Create auth module scaffold
c0ffe01 Initial commit

Each line contains:

  1. An abbreviated commit hash.
  2. The commit message.

The newest commit still appears first.

--oneline does not create different commits or change the history. It only changes how the existing history is displayed.

This compact format is useful when we want to scan the history quickly or find a commit ID.

A large repository may contain hundreds or thousands of commits.

To display only a specific number of recent commits, use:

Terminal window
git log --oneline -n 3

Example:

a3f8c21 Fix login crash on empty password
91bc044 Add login form validation
4e21aa0 Create auth module scaffold

Here:

  • --oneline uses the compact format.
  • -n 3 limits the result to the latest three commits.

The number can be changed:

Terminal window
git log --oneline -n 5

This displays the latest five commits.

Command Output
git log Full hash, author, date, and commit message
git log --oneline Abbreviated hash and message on one line
git log --oneline -n 3 Only the latest three commits in compact form

Interview question: What is the difference between git log and git log --oneline?

Section titled “Interview question: What is the difference between git log and git log --oneline?”

git log displays detailed commit history, including the full commit hash, author, date, and message. git log --oneline displays each commit in a compact single-line format containing an abbreviated hash and the commit message. Both commands read the same history and do not modify it.

No. git log shows commits that have already been recorded in the repository history.

Current staged, unstaged, and untracked changes are inspected using the commands explained in the previous lessons.

Does --oneline change or shorten the real commit ID?

Section titled “Does --oneline change or shorten the real commit ID?”

No. It only displays an abbreviated form of the commit ID. The commit still has its full ID internally.

No. It only limits how many commits are displayed. The rest of the history remains unchanged.

git log
Detailed commit history.
git log --oneline
Compact history: abbreviated hash + message.
git log --oneline -n 3
The latest three commits in compact form.
q
Exit the log pager and return to the shell.