TetSharing
Git & CLI tutorial · 12 chapters
  1. Terminal basics
  2. Working with files
  3. Pipes and redirection
  4. What Git is
  5. Staging and commits
  6. Viewing history
  7. Comparing changes
  8. Branches
  9. Merging
  10. Merge conflicts
  11. Undoing changes
  12. Remotes, push and pull

Final Git & CLI quiz
Cheat sheet: git commands
Cheat sheet: linux shell commands

Chapter 6 of 12 · By Ethan Cole · Updated November 21, 2026

Git log and git show: Explore a Project's History

History is the reason to use Git. Once a project has a few commits, git log lets you answer "what changed recently?", "who wrote this?" and "when did this break?".

git log

Plain git log lists commits newest first, each with its full hash, author, date and message. For daily use, shorter views are easier:

  • git log --oneline puts each commit on one line: short hash and summary.
  • git log -n 3 limits the output to the three latest commits.
  • git log --stat adds the files each commit touched.
  • git log --author="Ethan" and git log --grep="login" filter by author or by words in the message.
  • git log -- path/to/file shows only commits that changed that file.

When the list is longer than the screen, Git opens it in a pager; press q to get back to the prompt.

Hashes and HEAD

Every commit is identified by a 40-character hash such as 3f2a9c1.... You can refer to a commit by the first seven or so characters, as long as they are unique in the repository.

HEAD is Git's name for "the commit you are on now", usually the latest commit of your current branch. HEAD~1 means one commit before it, and HEAD~2 two before. These relative names are often easier than copying hashes.

git show

git show displays one commit: its details plus the exact lines it changed. With no argument it shows HEAD. git show HEAD~1 shows the previous commit, and git show HEAD:notes.txt prints a file as it was in that commit.

Terminal · bash + git · copy and run locally
git init -q
echo "v1" > app.txt
git add app.txt
git commit -q -m "Create app"
echo "v2" >> app.txt
git commit -q -am "Add second line"
echo "v3" >> app.txt
git commit -q -am "Add third line"
git log --oneline
git log -n 1 --format="%h %an: %s"
git show HEAD~1 --format="%s" --stat
git show HEAD~2:app.txt

Transcript (verified by our test suite in a fresh temp folder)

$ git init -q
$ echo "v1" > app.txt
$ git add app.txt
$ git commit -q -m "Create app"
$ echo "v2" >> app.txt
$ git commit -q -am "Add second line"
$ echo "v3" >> app.txt
$ git commit -q -am "Add third line"
$ git log --oneline
f862d68 Add third line
313ac69 Add second line
72d853c Create app
$ git log -n 1 --format="%h %an: %s"
f862d68 Ethan Cole: Add third line
$ git show HEAD~1 --format="%s" --stat
Add second line

 app.txt | 1 +
 1 file changed, 1 insertion(+)
$ git show HEAD~2:app.txt
v1

The transcript makes three small commits, then explores them. The --format option chooses exactly what to print: %h is the short hash, %s the subject line and %an the author name.

Custom formats

--format (also written --pretty=format:) is handy in scripts and for quick reports. git log --format="%h %an %s" gives a compact table of who did what. Run git log --oneline --graph --all once you have branches to see them drawn as a tree.

Common mistakes

  • Getting stuck in the pager. Press q.
  • Confusing HEAD~1 (the parent commit) with HEAD (the current one).
  • Copying a hash that is too short to be unique in a big repository; seven characters is usually enough.

Summary

  • git log --oneline and -n give a quick overview; filters narrow it down.
  • HEAD is the current commit; HEAD~1 is its parent.
  • git show reveals one commit's details and changes.

Quiz: Viewing history

1. Which command shows the latest two commits on one line each?

--oneline compresses each commit and -n limits how many are shown.

2. What does HEAD~1 refer to?

~1 means one step back from HEAD.

3. How do you leave git log's pager?

q quits the pager and returns to the prompt.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.