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:
git logto 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.
Practical example
Section titled “Practical example”Suppose we created the following commits in this order:
Initial commitCreate auth module scaffoldAdd login form validationFix login crash on empty passwordRunning:
git logmay 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 commitGit displays the newest commit first
Section titled “Git displays the newest commit first”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 passwordis the newest commit, while:
Initial commitis the oldest commit shown.
A beginner-friendly rule is:
Read
git logfrom top to bottom: newest first, older commits below.
What does HEAD mean here?
Section titled “What does HEAD mean here?”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.
Understanding each commit block
Section titled “Understanding each commit block”Every block in the output describes one commit.
Commit hash
Section titled “Commit hash”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
Section titled “Author”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 2026This shows when the commit was created.
Commit message
Section titled “Commit message”Fix login crash on empty passwordThe commit message explains the purpose of the checkpoint.
A useful message helps us understand why the change was saved without opening every file.
The parent chain
Section titled “The parent chain”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.
HEAD Newest
Fix login crash on empty password
git log starts reading the history from here.
Parent
Add login form validation
Parent
Create auth module scaffold
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.
Leaving the log screen
Section titled “Leaving the log screen”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:
qCompact history with git log --oneline
Section titled “Compact history with git log --oneline”The normal git log output contains detailed information for every commit.
For a shorter view, use:
git log --onelineExample:
a3f8c21 Fix login crash on empty password91bc044 Add login form validation4e21aa0 Create auth module scaffoldc0ffe01 Initial commitEach line contains:
- An abbreviated commit hash.
- 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.
Limiting the number of commits with -n
Section titled “Limiting the number of commits with -n”A large repository may contain hundreds or thousands of commits.
To display only a specific number of recent commits, use:
git log --oneline -n 3Example:
a3f8c21 Fix login crash on empty password91bc044 Add login form validation4e21aa0 Create auth module scaffoldHere:
--onelineuses the compact format.-n 3limits the result to the latest three commits.
The number can be changed:
git log --oneline -n 5This displays the latest five commits.
Full view versus compact view
Section titled “Full view versus compact view”| 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?”Short interview answer
Section titled “Short interview answer”
git logdisplays detailed commit history, including the full commit hash, author, date, and message.git log --onelinedisplays 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.
Common beginner misunderstandings
Section titled “Common beginner misunderstandings”Does git log show uncommitted changes?
Section titled “Does git log show uncommitted changes?”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.
Does -n 3 delete the older commits?
Section titled “Does -n 3 delete the older commits?”No. It only limits how many commits are displayed. The rest of the history remains unchanged.
English summary
Section titled “English summary”git logDetailed commit history.
git log --onelineCompact history: abbreviated hash + message.
git log --oneline -n 3The latest three commits in compact form.
qExit the log pager and return to the shell.