Git Log Command Explained with Options and Examples
In the previous blogs, we explored the basics of commits and how to amend them.
Now, it’s time to dive deeper into one of the most useful commands in Git — the git log command.
The git log command allows you to see the history of all commits in your repository, along with details like commit hash, author, date, and message.
Basic Git Log Command
git log
This command shows you the full commit history:
commit abc123...
Author: Gaurav Sharma <gaurav@example.com>
Date: Sat Aug 31 12:00:00 2025 +0530
Added user module
To exit the log pager, press q on your keyboard.
Disable Pager for Git Log
By default, git log opens in a pager (separate page view).
If you want the log to appear directly in the terminal, disable the pager:
git config --global pager.log false
Now git log outputs directly in your terminal.
One-Line Log View
For a concise history:
git log --oneline
Example output:
abc123 Added user module
def456 Login feature completed
ghi789 First commit
Reverse Order of Commits
If you prefer to see the oldest commit at the top:
git log --oneline --reverse
Show Limited Number of Commits
To show only the last 2 commits:
git log -2
Output:
abc123 Commit without staging
def456 Added untracked file
Log for a Specific File
To see commits related to a single file:
git log first.txt
Or in one-line format:
git log --oneline first.txt
Pretty Format Logs
You can customize log output using the --pretty option:
git log --pretty=format:"%h %an %ar %s"
Example output:
abc123 Gaurav 2 days ago Added user module
def456 Gaurav 5 days ago Commit without staging
Here:
%h→ Short commit hash%an→ Author name%ar→ Time ago%s→ Commit message
Coloring the Output
You can also apply colors:
git log --pretty=format:"%Cgreen%an%Creset %s"
This prints the author’s name in green.
Filtering Commits by Time
Show commits since a specific date:
git log --since="7 days ago"
Show commits before a specific date:
git log --before="2025-08-01"
Show commits between dates:
git log --after="2025-08-01" --before="2025-08-15"
Summary
In this blog, we learned:
- How to view commit history using
git log. - How to disable the pager for logs.
- Options like
--oneline,--reverse, and limiting commits. - Viewing commit history for a specific file.
- Formatting logs with
--pretty. - Adding colors and filtering commits by date.
In the next blog, we’ll continue exploring more advanced Git log features.
Keep Learning 🚀
👉 Subscribe to Learning Ocean – Subscribers get coupon codes for my courses, early access to blogs and courses, and even exclusive YouTube videos.
👉 My YouTube Channel – More videos, more fun, and lots of learning!
👉 📺 Watch this topic in video form
Stay curious, keep coding, and let’s make learning fun together! 🎉