Git Course 0%

Reading history

Beginner Git CLI VS Code UI IntelliJ UI GitLab UI GitHub UI ≈ 12 min

What you will learn

  • The log views that matter: oneline, graph, stat, and filters by path, author, date and text
  • git show for one commit and for a file as it was at a commit
  • git blame to find who last changed each line, and how to use it kindly

After this lesson you can

  • I can find when and why any line of any file changed, in under a minute

Why this matters

History is the reason version control exists, and reading it is a skill non-developers use more than developers: "when did this sentence change?", "who decided the default was 10?", "what went into the last release?". Three commands answer everything; the flags are the vocabulary.

git log: the list

The default output is long. Start with one line per commit:

Terminal
$ git log --oneline -5
c541c80 docs: add maintainer note
79c86c5 feat: add Eagle Ridge trail (#21)
dcc61f1 docs: describe the region and answer a data question (#28)
8e4a443 chore: add todo
a32e63b docs: remove tmp

Newest first; -5 limits the count. Add labels and a graph of branches:

Terminal
$ git log --oneline --graph --decorate -4
* c541c80 (HEAD -> main) docs: add maintainer note
* 79c86c5 feat: add Eagle Ridge trail (#21)
* dcc61f1 docs: describe the region and answer a data question (#28)
* 8e4a443 chore: add todo

The * column draws the chain; with branches and merges it forks and joins. --all includes every branch, not just the current one. (The starter configuration's git lg alias is exactly this.)

Filtering

Question Command
History of one file git log --oneline -- docs/faq.md
…following renames git log --oneline --follow -- docs/faq.md
Commits by one person git log --oneline --author=Ana
Since a date git log --oneline --since="2026-09-03" (also --until, --since="2 weeks ago")
Messages containing a word git log --oneline --grep="#21"
Commits that changed a given text git log --oneline -S "public domain"
Files touched per commit git log --stat --oneline -2
Between two points git log --oneline v1.2.0..main (what main has that the tag does not)
Terminal
$ git log --oneline -- docs/faq.md
dcc61f1 docs: describe the region and answer a data question (#28)
2f543f1 docs: explain how to add a trail (#27)
0d9eb38 docs: add map question to FAQ (#9)
8fa922e Initial import of trailguide
Terminal
$ git log --stat -2 --oneline
c541c80 docs: add maintainer note
 README.md | 2 ++
 1 file changed, 2 insertions(+)
79c86c5 feat: add Eagle Ridge trail (#21)
 data/trails.csv | 1 +
 1 file changed, 1 insertion(+)

A custom one-liner with dates is handy for reports:

Terminal
$ git log --pretty=format:"%h %ad %an  %s" --date=short -4
c541c80 2026-09-07 Ana  docs: add maintainer note
79c86c5 2026-09-07 Ana  feat: add Eagle Ridge trail (#21)
dcc61f1 2026-09-07 Ana  docs: describe the region and answer a data question (#28)
8e4a443 2026-09-09 Ana  chore: add todo

git show: one commit, or one file at a time

Terminal
$ git show HEAD --stat
commit c541c807612e2b322396e0defbaa843bdc7a0a27
Author: Ana <ana@northwind-trails.example>
Date:   Mon Sep 7 09:30:00 2026 +0200

    docs: add maintainer note

 README.md | 2 ++
 1 file changed, 2 insertions(+)

Without --stat, the full diff follows the message. git show <hash> works for any commit; git show v1.2.0 for a tag. A different use, easy to miss: a file as it was at a commit, printed without touching your working tree:

Terminal
$ git show HEAD~2:data/trails.csv
name,region,distance_km,difficulty
Ridge Loop,North,7.5,moderate
…
Twin Falls Track,South,8.8,moderate

<commit>:<path> is the syntax. Redirect it to a file (git show HEAD~2:data/trails.csv > old-trails.csv) to compare versions in a spreadsheet, or read it to answer "what did the guide say at release 1.2?".

git blame: who last touched each line

Terminal
$ git blame -L 1,5 docs/faq.md --date=short
^8fa922e (Ana 2026-09-01 1) # Frequently asked questions
^8fa922e (Ana 2026-09-01 2) 
^8fa922e (Ana 2026-09-01 3) ## Is Trailguide free?
^8fa922e (Ana 2026-09-01 4) 
^8fa922e (Ana 2026-09-01 5) Yes. It is a practice project for the Git Course and can be used, changed and shared freely.

Each line: the commit that last changed it (^ marks the initial commit), the author, the date, the line number, the line. -L 1,5 limits to lines 1–5. Blame answers "which commit put this here?"; then git show <hash> answers why. Two cautions: blame shows the last change, which may be a reformatting rather than the author of the idea (-w ignores whitespace changes, -M follows moved lines); and the name is a starting point for a question, not for an accusation. Many teams say "annotate" for that reason.

In the tools

Everything above. Long output opens the pager: Space forward, b back, /word to search, q to quit. --no-pager before log prints straight to the screen.

Common mistakes

  • Scrolling through the default git log looking for something. Use --oneline and a filter.
  • Blaming a line and stopping there. The last change may be a rename or whitespace fix; use -w, and check the file's history for the real origin.
  • Forgetting -- before a file name when a branch has the same name.
  • Looking for uncommitted work in the log. The log has commits only; git status and git diff have the rest.

Try it yourself

Goal: trace one line of the playground FAQ to its commit.

  1. Run git blame docs/faq.md --date=short and pick any line's hash.
  2. Run git show <hash> --stat for that hash.
  3. Run git log --oneline -- docs/faq.md and find the same hash in the list.
  4. Run git show <hash>:docs/faq.md | head -5 to read the file as it was at that commit.

Expected result: the blame hash appears in the file's log; git show gives its message, author, date and files; the <hash>:<path> form prints the old content.

Show solution

Blame → show → log is the standard chain: find the commit, read its story, see it in context. In a fresh playground every line points at your import commit; after the earlier exercises, lines you added point at your later commits.

Check yourself

1. Which command lists only the commits that changed docs/faq.md?
2. How do you read a file exactly as it was two commits ago without changing your working tree?
3. git blame shows Ben on a line you know Ana wrote. Most likely reason?

Key terms

Log Commit Hash (SHA) HEAD