As software evolves over months and years, inspecting historical commits becomes crucial for tracking features, conducting post-mortems on bugs, and reviewing peer contributions. The git log command is Git's primary time machine.
Executing git log lists the commits made in that repository in reverse chronological order (newest commit first):
1 commit 7b3f81e28d4c5a9b0c2d4e6f8a0b1c2d3e4f5a6b (HEAD -> main)
2 Author: Sumit Sharma <sumit@mskinstitute.com>
3 Date: Mon Sep 15 10:30:00 2026 +0530
4
5 feat(auth): add JWT token expiration check
6
7 commit 4a2c91d8f1e3a5b7c9d0e2f4a6b8c0d2e4f6a8b0
8 Author: Neha Gupta <neha@mskinstitute.com>
9 Date: Sun Sep 14 16:15:22 2026 +0530
10
11 fix(css): fix mobile navbar z-index overflow
Note [!NOTE]
When the log output exceeds your terminal height, Git pages the output using less.
- Press Spacebar to scroll down one page.
- Press b to scroll up.
- Press q to quit and return to the command prompt.
A. Compact Single-Line View (--oneline) Condenses each commit into its short 7-character hash and commit title:
Output:
1 7b3f81e (HEAD -> main) feat(auth): add JWT token expiration check
2 4a2c91d fix(css): fix mobile navbar z-index overflow
3 9f1e82b docs: update project README
B. Limit Output Count (-n <number>) View only the last $N$ commits:
C. Show Changed Files and Stats (--stat) Displays the files modified, number of lines inserted (+), and deleted (-):
D. Show Full Line-by-Line Code Patches (-p) Shows the actual line diff introduced by each commit:
When multiple developers are branching and merging, visualizing the branch tree topology directly in your terminal is invaluable:
1 git log --graph --oneline --all --decorate
Terminal Output: 1 * 7b3f81e (HEAD -> main) Merge branch 'feature-payment'
2 |\
3 | * 3a89e12 (feature-payment) feat: integrate Stripe checkout API
4 | * 2c510fa feat: add webhook listener
5 * | 4a2c91d fix: update landing page typography
6 |/
7 * 9f1e82b Initial commit
Pro Tip: Create an Alias for Visual Log Save this command permanently as an alias:
1 git config --global alias.lg "log --graph --oneline --all --decorate"
2
3 # Now simply run:
4 git lg
Git lets you filter commit history with precision:
1 # 1. Filter by author
2 git log --author = "Sumit"
3
4 # 2. Filter by date range
5 git log --since = "2 weeks ago" --until = "yesterday"
6
7 # 3. Filter by search keyword in commit messages
8 git log --grep = "bugfix"
9
10 # 4. Filter history of a specific single file
11 git log -p src/utils/auth.js
Interactive Quiz • Knowledge Check
Practice Quiz What is the default ordering of commits displayed by git log?
A Alphabetical order by commit author
B Reverse chronological order (newest commits first)
C Chronological order (oldest commits first)
D Random order
Which key allows you to exit the Git log pager and return to the terminal prompt?
Which flag formats the output of git log into a clean single-line representation per commit?
A --compact
B --short
C --oneline
D --inline
Which combination of flags renders an ASCII graphical tree of all branches and merge topologies in the terminal?
A git log --tree
B git log --graph --oneline --all
C git log --visual
D git log --branches
How can you view the commit history for changes that specifically affected only src/db.js?
A git log src/db.js
B git show src/db.js
C git inspect src/db.js
D git track src/db.js