CHAPTER 7 · 1 lesson · 13 exercises

Viewing History and Differences

Inspect history with git log, view commit details with show, compare changes with diff, and trace lines with blame.

0 / 13 solved

Now that you know how to commit and share, this chapter is about inspecting and reading history.

The question that comes up most in real development:

> When was this line written, by whom, and why?

Git provides four primary tools to answer this:

  • git log … display commit history (with options like --oneline, --graph, -n, --stat)
  • git show … inspect the exact diff and details of a single commit
  • git diff … compare changes line by line between working tree, staging area, and commits
  • git blame … show which commit and author last modified each line of a file

git diff compares different snapshots depending on its arguments. Understanding these comparisons clarifies the true purpose of the staging area.

All inspection commands are completely read-only and safe. Run them freely whenever you need to explore.

Lessons in this chapter

log and diff

  1. 07Inspecting history and diffs (log / show / diff / blame)Master git log, show, diff, and blame to inspect commit histories, analyze code differences across areas, and trace causes of bugs.Go to the exercises

Next up is “Cloning and Tagging”. Clone remote repositories, configure remote URLs, and mark release versions with tags.