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:
| Command | Shows |
|---|---|
git log | every commit in full |
git log --oneline | one line each: short hash and subject |
git log --stat | which files each commit changed, and how much |
git log -p | the 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.
- List the history on one line per commit
- See which files each commit changed with
--stat - 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
67e435dHEAD →main Cover the leche flan with foilba04ca2Add lumpiang shanghai recipe98a5edcAdd a script that builds the index paged078487Make the sinigang steps clearer145dc1eAdd pancit bihon recipe52d1f4dSay how much salt goes in the adobo1c17fadAdd a README9c53888Add leche flan recipe1f359a2Add sinigang recipe601c654Add 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:
| Name | Means |
|---|---|
HEAD | the commit you're on |
HEAD~1 | its parent: one commit back |
HEAD~3 | three 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-10or--since="1 week ago": commits after a date;-pwith 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 52d1f4d Say how much salt goes in the adobo 601c654 Add adobo recipe
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
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.
- Git documentation: git-log: --oneline, --stat, -p, --author, --since and paths
- Git documentation: git-show: showing a commit with its diff
- Git documentation: gitrevisions: naming commits: hashes, HEAD, ~ and ^
- Pro Git: Viewing the Commit History: useful log options