Tour of Git
Git Basics / Lesson 1.6

git log — Viewing Commit History

The git log command shows the history of commits in your repository. It's how you look back at what happened, who did it, and when.

Reading the Log

When you run git log, each entry shows:

  • Commit hash — The full SHA identifier (e.g., a1b2c3d4e5f6...)
  • Author — Name and email of the person who made the commit
  • Date — When the commit was created
  • Message — The description the author wrote

The log is displayed in reverse chronological order — newest commits first.

Useful Flags

--oneline

Condenses each commit to a single line showing just the short hash and message:

git log --oneline

Output looks like:

a1b2c3d Add second file
f4e5d6a Add first file
9b8c7d6 Initial commit

-n (limit)

Show only the last N commits:

git log -3

--all

Show commits from all branches, not just the current one:

git log --oneline --all

Try it!

The repository is already initialized. Create three commits and explore the log:

  1. Create a file: echo "hello" > hello.txt
  2. Stage and commit: git add hello.txt then git commit -m "Add hello file"
  3. Create another file: echo "world" > world.txt
  4. Stage and commit: git add world.txt then git commit -m "Add world file"
  5. Create a third file: echo "!" > exclaim.txt
  6. Stage and commit: git add exclaim.txt then git commit -m "Add exclaim file"
  7. View the full log: git log
  8. View the compact log: git log --oneline

Notice how --oneline gives you a quick overview while the full log has all the details.

Searching the Log

You can also filter commits by author or message content:

git log --author="Alice"
git log --grep="fix"

These become invaluable as your project history grows.

🎯

Goal

Create 3 commits and explore the log output

Terminal
$

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