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

Git log Command

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

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.