← Back to Git Course | Chapter 2: Basic Commands | Lesson 11 of 18

Git log Command

git log is like flipping through the photo album from the newest picture backward, reading who took each one, when, and what the caption says.
Syntax
bash
git log
git log --oneline
git log -n number
git log --author="name"

Viewing Commit History

git log walks backward through your commit history, newest first, printing each commit's full hash, author, date, and message -- add --oneline to compress each entry to a single line when you just need a quick overview.

Example: Viewing Commit History

bash
git log
git log --oneline

Limiting the Log Output

On a long-running project the full log can stretch for thousands of entries, so git log -n 5 (or any number) limits the output to just the most recent commits, which is usually all you actually need to check.

Example: Limiting the Log Output

bash
git log -n 5

Filtering Logs by Author

On a team project, git log --author="name" filters the history down to commits from one specific person, which is useful for reviewing someone's recent work or tracking down who touched a particular area.

Example: Filtering Logs by Author

bash
git log --author="Priya"

Filtering Logs by Date

git log --since="2 weeks ago" --until="yesterday" (or specific dates) filters commits to a date range, which is the fastest way to review exactly what changed during a sprint or before a release.

Example: Filtering Logs by Date

bash
git log --since="2 weeks ago" --until="yesterday"

Visualizing History with Graphs

git log --graph --oneline --all draws an ASCII diagram of how your branches diverged and merged over time, turning an otherwise linear list into a visual map that makes complex branching history much easier to follow.

Example: Visualizing History with Graphs

bash
git log --graph --oneline --all
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Scrolling through the full git log output, when git log --oneline gives one line per commit.
  2. Pressing keys wrongly in the pager and not knowing that q exits it.
  3. Expecting git log to show commits from other branches, when it shows only the history reachable from the current one unless you use --all.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.