git log & git show

Read the history

Lesson 4 of 20 · 8 min · Module 1: Your first repository

History is only useful if you can read it. Every commit has an author, a date, a message, and a unique name: its hash.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Read git log and git log --oneline
  • Filter the history by file
  • Inspect one commit with git show

The idea

git log lists commits, newest first. git log --oneline shows one line each: the short hash and the message. git show displays one commit together with its changes; without arguments, it shows the latest. HEAD means the commit you are on and HEAD~1 the one before it. Add -- file at the end of git log to see only the commits that changed that file.

git log --oneline
git log --oneline -- style.css
git show HEAD~1

01Newest first

git log lists commits from the newest to the oldest. With --oneline you get the short hash and the message. The hash is the commit's unique name; its first seven characters are usually enough to refer to it.

git log --oneline
Output
4abfd2a (HEAD -> main) Say what the site is about
ac3e6fd Use a darker heading colour
bcd3497 Add about page, menu and README
9e3de74 Add home page and styles

02Ask about one file

Put -- and a file name at the end to see only the commits that changed that file.

git log --oneline -- style.css
Output
ac3e6fd Use a darker heading colour
9e3de74 Add home page and styles

03Look inside a commit

git show prints a commit with its diff: lines starting with - were removed and lines starting with + were added. HEAD is the commit you are on; HEAD~1 is the one before it.

git show HEAD~1
Output
commit ac3e6fdf86cc4a1f0362f268ef28d6e5f69a33fb
Author: Sam Rivera <[email protected]>
Date:   Wed Oct 14 11:21:00 2026 +0000

    Use a darker heading colour

diff --git a/style.css b/style.css
index b346392..60a5962 100644
--- a/style.css
+++ b/style.css
@@ -1,2 +1,2 @@
 body { font-family: sans-serif; margin: 2rem; }
-h1 { color: #2f6f4e; }
+h1 { color: #1f3c88; }

Your turn

Your website now has a few commits, one of them by your teammate Sam. List the history with one line per commit. Then list only the commits that changed style.css, and show in full the commit that changed the heading colour (it is HEAD~1, or use its hash). Who made it?

What the checks look for

  • Lists every commit, one per line
  • Lists only the commits that changed style.css
  • Shows Sam's commit in full
Try it in the editor →

Take this with you

git log --oneline gives you the overview; git show tells the whole story of one commit.

Go a little further

Try git log --oneline --author=Sam and git log --stat, which lists the files each commit changed.

Learn Git & GitHub for free

20 short lessons with real code and instant checks.

See the whole course →