Lesson Completion
Back to course

git log

Beginner
10 minutes4.8GitPlay to LearnLearn by Story

The Hook (The "Byte-Sized" Intro)

git log turns your project into a Netflix episode guide — every commit is an episode with a title, a date, and a synopsis. The raw output is noisy, but with the right flags, you can slice, filter, and format history like a search engine. The developers who debug fastest aren't the smartest — they're the ones who know git log.

📖 What is git log?

git log displays the commit history of your repository. By default, it shows every commit in reverse chronological order with full details. But its real power comes from flags — you can filter by author, date, file, message, and more.

Conceptual Clarity

  • git log reads from the current branch's HEAD backward through the parent chain
  • Each entry shows: hash, author, date, message
  • The log is local — it shows the history in your repository (use git fetch first to update remote history)
  • Flags let you customize the output format and filter results
  • Combine flags to build powerful queries

Real-Life Analogy

git log is like the "Recently Edited" history in Google Docs — but with superpowers. Imagine being able to filter Google Docs history to show only edits by Alice, in January, to Chapter 3, that mention "refactor."

Visual Architecture

flowchart RL C5["📸 HEAD<br/>a1b2c3d"] --> C4["📸 e4f5g6h"] C4 --> C3["📸 i7j8k9l"] C3 --> C2["📸 m0n1o2p"] C2 --> C1["📸 root<br/>q3r4s5t"] style C5 fill:#0f3460,stroke:#53d8fb,color:#53d8fb style C4 fill:#1a1a2e,stroke:#ffd700,color:#ffd700 style C3 fill:#1a1a2e,stroke:#ffd700,color:#ffd700 style C2 fill:#1a1a2e,stroke:#e94560,color:#e94560 style C1 fill:#1a1a2e,stroke:#e94560,color:#e94560

Why It Matters

  • Debugging: Find exactly which commit introduced a bug by searching messages or diffs.
  • Code review: Understand how a feature evolved over time.
  • Accountability: See who changed what and when.
  • Releases: Identify what's changed since the last release tag.

Code

bash
# ─── Default: full details (verbose) ─── git log # Output: hash, author, date, full message for each commit # ─── Compact: one line per commit ─── git log --oneline # Output: # a1b2c3d (HEAD -> main) Add user auth # e4f5g6h Fix navbar overflow # i7j8k9l Initial commit # ─── Limit to last N commits ─── git log --oneline -5 # ─── Visual branch graph ─── git log --oneline --graph --all # Output: # * a1b2c3d (HEAD -> main) Merge feature/login # |\ # | * b2c3d4e Add login form # | * c3d4e5f Add auth API # |/ # * d4e5f6g Update README # ─── Filter by author ─── git log --author="Nikhil" # ─── Filter by date range ─── git log --after="2026-01-01" --before="2026-02-01" # ─── Filter by commit message keyword ─── git log --grep="fix" --oneline # ─── Show only commits that touched a specific file ─── git log --oneline -- src/app.js # ─── Show the diff in each commit ─── git log -p -1 # Shows the full diff of the most recent commit # ─── Show stats (files changed, insertions, deletions) ─── git log --stat -3 # ─── Custom format ─── git log --pretty=format:"%h | %an | %ar | %s" -5 # Output: # a1b2c3d | Nikhil | 2 hours ago | Add user auth # e4f5g6h | Nikhil | 1 day ago | Fix navbar

Essential git log Flags

FlagPurposeExample
--onelineCompact formatgit log --oneline
-n NLimit to N commitsgit log -5
--graphASCII branch visualizationgit log --graph --oneline
--allShow all branchesgit log --all --oneline
--authorFilter by authorgit log --author="Alice"
--grepSearch commit messagesgit log --grep="fix"
--after/--beforeFilter by dategit log --after="2026-01-01"
-pShow diffsgit log -p -1
--statShow file change statsgit log --stat
-- <file>Filter by file pathgit log -- README.md
--pretty=format:Custom output formatSee example above

Key Takeaways

  • git log is your window into commit history — use it constantly.
  • --oneline and --graph are the two flags you'll use most.
  • Combine --author, --grep, --after, and -- <file> to create precise queries.
  • git log -p shows the actual code changes alongside each commit.

Interview Prep

  • Q: How do you find all commits by a specific author? A: Use git log --author="Name". This filters the log to show only commits where the author field matches the given string.

  • Q: How can you see which commits changed a specific file? A: Use git log -- <filepath>. For example, git log --oneline -- src/app.js shows all commits that modified that file.

  • Q: What is the difference between git log and git log --all? A: git log shows the history reachable from the current HEAD (current branch only). git log --all shows commits from all branches and tags, which is useful for seeing the full repository graph.

Topics Covered

Git BasicsGit Fundamentals

Tags

#git#log#history#beginner-friendly

Last Updated

2026-02-12