The git log command is used to view the commit history of a Git repository. It helps you see previous commits, commit messages, authors, dates, and commit identifiers.
git log command only displays
information about commits that already exist in the repository.
git log is a Git command used to display the commit history of a repository.
git log
It shows information about commits in reverse chronological order, with the most recent commit normally appearing first.
The git log command is useful when you want to understand
how a project has changed over time.
The basic syntax is:
git log
Run this command from inside a Git repository.
Suppose a project contains three commits. Running:
git log
may display information similar to:
commit 7a91bc2...
Author: Student
Date: ...
Add contact page
commit 3f82de1...
Author: Student
Date: ...
Add homepage
commit 1d72abc...
Author: Student
Date: ...
Initial commit
Every commit has a unique identifier called a commit hash.
commit 7a91bc2...
The hash is used by Git to identify a particular commit.
The log normally displays the author associated with each commit.
Author: Student <student@example.com>
Git gets this information from the user's Git configuration.
The commit history also displays date and time information associated with commits.
Date: Tue Sep 24 12:00:00 2026 +0530
The exact format can vary depending on Git configuration and terminal.
The commit message describes the changes represented by the commit.
git commit -m "Add login page"
The message can later be seen in the output of git log.
By default, git log displays the most recent commits first.
Latest Commit
↓
Previous Commit
↓
Older Commit
↓
Initial Commit
The --oneline option provides a compact version of the commit history.
git log --oneline
This is useful when you want to quickly scan many commits.
7a91bc2 Add contact page
3f82de1 Add homepage
1d72abc Initial commit
Each line contains a shortened commit identifier followed by the commit message.
You can use:
git log -1
This limits the output to the latest commit.
You can specify how many commits you want to display. For example:
git log -3
This displays the three most recent commits.
You can combine options:
git log --oneline -5
This shows a compact list of the five most recent commits.
The git show command can be used when you want more detailed information about a specific commit.
git show 7a91bc2
The commit identifier can be obtained from git log.
The normal git log command shows the history reachable
from the current branch.
git log
This makes it useful for understanding the history of the branch you are currently working on.
You can include histories from all local branches with:
git log --all
This can help when exploring a repository with multiple branches.
The --graph option displays an ASCII graph showing relationships between commits.
git log --graph
This becomes especially useful when a project contains branches and merges.
You can combine the graph and compact format:
git log --oneline --graph
This provides a compact visual representation of commit history.
A commonly useful combination is:
git log --oneline --graph --all
This can display a compact graph containing commits reachable from all local references.
The --grep option can search commit messages.
git log --grep="login"
This searches for commits whose messages match the specified pattern.
You can filter commits by author using:
git log --author="Student"
This can be useful in repositories with multiple contributors.
The --stat option provides a summary of file changes associated with commits.
git log --stat
It can show files changed and summarized line changes for commits.
The log command can also show patch information:
git log -p
This displays the changes introduced by commits in patch format.
You can view commits related to a specific file:
git log -- index.html
The -- separates revision options from the file path.
git log
git log --oneline
git log -5
git log --oneline -5
git log --all
git log --graph
git log --oneline --graph --all
git log --stat
git log -p
These options help you inspect project history in different ways.
git log outside a Git repository.--oneline when a compact history is preferred.git status
git add .
git commit -m "Update project"
git log
git log --oneline
git log --oneline --graph --all
This workflow lets you create commits and then inspect the history in different formats.
git init
touch index.html
git add index.html
git commit -m "Create homepage"
touch about.html
git add about.html
git commit -m "Create about page"
git log --oneline
The final command displays the commit history in a compact format.
The git log command is used to inspect the commit history of a Git repository.
git log
For a shorter history, use:
git log --oneline
For a visual branch history, use:
git log --oneline --graph --all
Understanding git log helps you track how a project has
developed and locate important commits in its history.
git log --oneline provides a compact history.git log -5 shows the five most recent commits.git log --all includes history from all local references.git log --graph displays a commit graph.git log --grep can search commit messages.git log --author can filter commits by author.git log --stat displays file-change statistics.git log -p displays patch information.git log -- filename shows commits related to a file.Question: Which Git command is used to view the commit history?