Looking back and undoing · lesson 1 of 7
Commands and ideas in this lesson
Agit logthe history, newest first
Bgit showone commit and its changes
C-- file, --authornarrow the list
DHEAD~3three commits back

Reading history

Last updated

Kusina has two weeks of commits now. In this lesson you'll read its history in a few useful shapes, look inside any commit, narrow the list down to one file or one person, and name commits by counting back from where you are.

By the end of this lesson you can

  • List history with git log, --oneline, --stat and -p
  • Show one commit with git show
  • Narrow the log to a file, an author or a date
  • Name commits with hashes, short hashes and HEAD~n

Shapes of the log

git log lists commits, newest first, with each one's hash, author, date and message. It has many options; four cover most needs:

CommandShows
git logevery commit in full
git log --onelineone line each: short hash and subject
git log --statwhich files each commit changed, and how much
git log -pthe full diff of every commit (p for patch)

Add a number to see only the latest few: git log --oneline -3. In a real terminal, a long log opens in a pager: scroll with the arrow keys or Space, and press q to get back. The sandbox prints everything.

Look inside a commit

git show shows one commit: its details and its diff. With no name it shows the newest. Give it a hash to see any other: git show 601c654. Add --stat for just the list of files.

Git sandbox
  1. List the history on one line per commit
  2. See which files each commit changed with --stat
  3. Look inside the newest commit with git show

Working folder

no changes

Staging area

nothing staged

Repository

10 commits on main

You are in ~/kusina, which has ten commits from two weeks of work.

Commit graph

  1. 67e435d HEAD →main Cover the leche flan with foil
  2. ba04ca2 Add lumpiang shanghai recipe
  3. 98a5edc Add a script that builds the index page
  4. d078487 Make the sinigang steps clearer
  5. 145dc1e Add pancit bihon recipe
  6. 52d1f4d Say how much salt goes in the adobo
  7. 1c17fad Add a README
  8. 9c53888 Add leche flan recipe
  9. 1f359a2 Add sinigang recipe
  10. 601c654 Add adobo recipe

Naming commits: hashes and HEAD~n

Every commit has a 40-character hash. You can use just the start of it, as long as no other commit starts the same way. Seven characters is Git's usual short form.

HEAD means "the commit you're on now", usually the newest on your branch. Counting back from it:

NameMeans
HEADthe commit you're on
HEAD~1its parent: one commit back
HEAD~3three commits back

So git show HEAD~3 shows the commit three steps before the newest, and git diff HEAD~3 HEAD compares then and now. Git's documentation page gitrevisions lists every way to name a commit.

Find a change

Give git log a file after --, and it lists only commits that changed that file: git log --oneline -- adobo.md. Other filters:

  • --author=Joaquin: commits whose author name or email contains "Joaquin";
  • --since=2026-03-10 or --since="1 week ago": commits after a date;
  • -p with a file: every change to that file, in full.

Lola Remy wants to know two things: when the adobo's salt changed, and what Joaquin did.

<GitSandbox scene="history" tasks=List only the commits that changed <code>adobo.md</code>,(w) => w.history.some((l) => re.test(l)),See exactly what the salt commit changed (use its hash, or <code>git log -p -- adobo.md</code>),(w) => cs.every((c) => c(w)),List only Joaquin’s commits,(w) => w.history.some((l) => re.test(l)),Show the commit three back from the newest with <code>HEAD~3</code>,(w) => w.history.some((l) => re.test(l)) />

Spot the trap: newest first

git log --oneline -- adobo.md
git log --oneline -- adobo.md
52d1f4d Say how much salt goes in the adobo
601c654 Add adobo recipe
Spot the trapAna

Ana reads the log above, top to bottom, as a story: “First the salt was set, then the recipe was added.”

What happens if…

Check what you learned

Which command lists only the commits that changed sinigang.md?
You’re on the newest commit. What does HEAD~2 name?
In git log --oneline, which line is the oldest commit?

Sources

Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.

All sources for Simple Git