Exploring History with git log

Your repo is a time machine, and git log is the dial. By the end of this lesson you'll read history compactly, draw your branches as a graph, filter commits by author, message, date, and file, and inspect any single commit in full with git show.

Learn Exploring History with git log in our free Git course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Git course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

1️⃣ git log Basics & --oneline

git log walks backwards through the current branch, newest first, showing each commit's hash, author, date, and message. The full output is verbose, so --oneline collapses each commit to a single line. Limit the count with -n 3 (or just -3 ), and press q to leave the pager.

2️⃣ Visualising with --graph --all

Text history hides the shape of your branches. git log --oneline --graph --all draws the whole repository as an ASCII graph: --graph adds the branch/merge lines, and --all includes every branch rather than just the one you're on. Learn this command early — it's the fastest way to picture what your branches are doing.

3️⃣ Filtering the History

Big projects need filters. --author keeps commits by one person, --grep searches commit messages , --since / --until bound a time window, and -- <path> limits to commits that touched one file. These all combine, so you can ask very specific questions of your history.

4️⃣ Inspecting One Commit with git show

Once git log helps you find the commit, git show zooms in. It prints the commit's metadata and the exact diff it introduced. Give it HEAD , a short hash, or any commit reference; add --stat for just the changed-files summary.

Your turn. Read history compactly, graph it, then search messages. Fill in the three blanks.

📋 Quick Reference

No commands given this time — just the questions. Answer each with a single git log or git show command.

Practice quiz

What does show?

  • Your branches
  • The staging area
  • The commit history of the current branch
  • Remote URLs

Answer: The commit history of the current branch. git log lists commits, newest first, on the current branch.

What does the flag do?

  • Condenses each commit to a single line (short hash + message)
  • Shows only one commit
  • Shows commits from one author
  • Limits to one branch

Answer: Condenses each commit to a single line (short hash + message). --oneline prints a compact one-line summary per commit.

What does add to git log?

  • A bar chart of file sizes
  • Author photos
  • A pie chart
  • An ASCII drawing of branch and merge structure

Answer: An ASCII drawing of branch and merge structure. --graph draws the branching/merging topology as ASCII lines on the left.

What does do in ?

  • Shows every file
  • Includes commits from ALL branches, not just the current one
  • Shows all authors only
  • Disables paging

Answer: Includes commits from ALL branches, not just the current one. --all includes the history of every branch and ref, not just HEAD's branch.

How do you limit git log to the last 5 commits?

  • git log -5 (or -n 5)
  • git log --last 5
  • git log --limit=5
  • git log HEAD~5

Answer: git log -5 (or -n 5). git log -5 (equivalently -n 5) shows the five most recent commits.

Which flag filters commits by who made them?

  • --committer-only
  • --by=Name
  • --author=Name
  • --user=Name

Answer: --author=Name. --author=Name keeps only commits whose author matches the pattern.

Which flag searches commit MESSAGES for a word?

  • --message
  • --grep=word
  • --search=word
  • --find=word

Answer: --grep=word. --grep=word filters to commits whose message matches the pattern.

How do you see the history of just one file?

  • git log onlyfile
  • git log --file path
  • git history file
  • git log -- path/to/file

Answer: git log -- path/to/file. git log -- <path> limits the log to commits that touched that path.

What does display?

  • Only the message
  • The commit's metadata AND its full diff
  • Just the author
  • The whole repo

Answer: The commit's metadata AND its full diff. git show prints the commit details together with the patch it introduced.

In , the short string before each message is...

  • The branch name
  • The author's initials
  • An abbreviated commit hash
  • A line number

Answer: An abbreviated commit hash. It's the abbreviated SHA-1 hash uniquely identifying that commit.