What does the git log command do?
Learn what the git log command does, how to filter and format commit history, and the most useful flags like --oneline, --graph, -p, and --author.
Expected Interview Answer
git log displays the commit history of the current branch, showing each commit's hash, author, date, and message in reverse chronological order so you can trace what changed and when.
By default it prints a full entry per commit, but flags reshape that output enormously: --oneline compresses each commit to a single line, --graph draws the branch and merge topology with ASCII lines, -p shows the actual diff introduced by each commit, and --author or --since filter by contributor or time range. Because it walks the commit graph rather than just a flat list, git log can also show history for a single file, between two branches, or across merges.
- Traces exactly what changed and when in a project
- Filters history by author, date, path, or message
- Visualizes branch and merge structure with --graph
- Helps locate the commit that introduced a bug
- Essential for code review and debugging regressions
AI Mentor Explanation
git log is like the full scorecard of a match, listing every over bowled, who bowled it, and what happened on each ball, in order from the first over to the last. You can filter it to just one bowler's overs or just the boundaries, the same way flags narrow git log to one author or one file. Without the scorecard, nobody could reconstruct how the innings actually unfolded.
Step-by-Step Explanation
Step 1
Run git log
Shows the current branch's commits in reverse chronological order with hash, author, date, and message.
Step 2
Compact with --oneline
git log --oneline shows one line per commit: a short hash plus the message, for a fast overview.
Step 3
Visualize branches with --graph
git log --oneline --graph --all draws ASCII lines showing branch and merge topology.
Step 4
Filter the history
Use --author="name", --since="2 weeks ago", or a file path to narrow results to what matters.
Step 5
See actual changes
git log -p shows the diff introduced by each commit, useful when tracing down a specific change.
What Interviewer Expects
- Knows git log shows commit history in reverse chronological order
- Can name useful flags: --oneline, --graph, -p, --author, --since
- Understands it can be scoped to a file, branch range, or author
- Mentions using it to locate when/why a bug was introduced
- Knows the difference between git log and git show
Common Mistakes
- Not knowing --oneline exists and always reading full verbose output
- Forgetting git log only shows the current branch unless --all is passed
- Confusing git log with git status or git diff
- Not realizing you can filter by file path at the end of the command
Best Answer (HR Friendly)
“git log shows the timeline of every change made to a project — who made it, when, and what the message said — so you can trace the project's history. You can filter it to focus on one person, one time period, or one file when you need to find something specific.”
Code Example
git log --oneline --graph --all
git log --author="Priya" --since="2 weeks ago"
git log -p -- src/app.py
git log --stat -3Follow-up Questions
- How is git log different from git show?
- How would you find which commit introduced a specific bug?
- What does git log --stat display that plain git log does not?
- How do you view the log for just one file's history?
- What is the difference between git log and git reflog?
MCQ Practice
1. What order does git log display commits in by default?
git log shows the most recent commit first and walks backward through history by default.
2. Which flag compresses each commit to a single line?
--oneline shows a short hash and the commit message on a single line per commit, for a fast overview.
3. How do you see the actual code changes introduced by each commit in the log?
The -p (patch) flag shows the diff each commit introduced, alongside its normal metadata.
Flash Cards
What does git log show by default? — The current branch's commit history, newest first, with hash, author, date, and message.
What does git log --oneline do? — Compresses each commit to a short hash and message on a single line.
How do you filter git log by author? — git log --author="name" shows only commits by that author.
What does git log -p add to the output? — The actual diff (patch) introduced by each commit.