What is git log?

Why Interviewers Ask This

This is a classic screening question for Git & GitHub roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.

Answer

git log displays the commit history of the current branch, showing commits in reverse chronological order (newest first). Default output: commit hash, author, date, and message. Useful options: git log --oneline — compact single-line format (short hash + message); git log --graph — ASCII art graph of branch topology; git log --oneline --graph --all — visual history of all branches (very useful for understanding repo state); git log -5 — show last 5 commits; git log --author="Alice" — filter by author; git log --since="2024-01-01" --until="2024-06-01" — date range; git log --grep="bug fix" — search commit messages; git log -p / --patch — show diff for each commit; git log --stat — show changed files summary per commit; git log file.txt — history of a specific file; git log main..feature — commits in feature not yet in main. Format: git log --format="%h %an %s" — custom output (hash, author name, subject). git log is one of the most powerful and frequently used Git commands for understanding a project's history.

Pro Tip

This topic has Git & GitHub-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.