Tour of Git
History & Undoing Changes / Lesson 3.2

git log — Advanced History

You've already used git log to see commits. Now let's explore its powerful options for filtering and formatting.

Useful Flags

  • git log --oneline — Compact one-line format
  • git log -n 3 — Show only the last 3 commits
  • git log --graph — ASCII art showing branch structure
  • git log --all — Show commits from all branches, not just current

Combining Flags

The real power comes from combining flags:

git log --oneline --graph --all

This gives you a compact visual overview of your entire repository — branches, merges, and all.

Try it!

Build up a history with branches, then explore it:

  1. Make three commits on main:
    • echo "v1" > app.txt && git add app.txt && git commit -m "Version 1"
    • echo "v2" > app.txt && git add app.txt && git commit -m "Version 2"
    • echo "v3" > app.txt && git add app.txt && git commit -m "Version 3"
  2. View compact log: git log --oneline
  3. View only last 2: git log --oneline -n 2

You should see 3 commits with their short SHAs and messages.

Reading the Output

a1b2c3d (HEAD -> main) Version 3
e4f5g6h Version 2
i7j8k9l Version 1
  • The SHA prefix (a1b2c3d) uniquely identifies each commit
  • (HEAD -> main) shows where you currently are
  • Messages appear in reverse chronological order (newest first)
🎯

Goal

Create 3 commits and view the log with --oneline flag

Terminal
$

No commits yet. Run `git init` and create your first commit.