Tour of Git
History & Undoing Changes / Lesson 3.1

Exploring History

One of Git's greatest strengths is its ability to let you travel through time. Every commit is a snapshot you can inspect, compare, or return to.

Tools for Exploring

Git provides several commands for understanding what happened and when:

  • git log — View the commit timeline
  • git diff — Compare file versions between states
  • git stash — Temporarily shelve uncommitted work
  • git reset — Move HEAD and undo commits

The Commit Timeline

Every commit records:

  • What changed (the tree/snapshot)
  • Who made the change (author)
  • When it happened (timestamp)
  • Why it was made (commit message)
  • What came before (parent commits)

This forms a chain you can walk backwards through at any time.

Three Areas to Compare

When using git diff, you're comparing between three areas:

Working Directory ←→ Staging Area ←→ Last Commit
     (editing)         (git add)       (git commit)
  • git diff — Working directory vs. staging area
  • git diff --staged — Staging area vs. last commit
  • git diff HEAD — Working directory vs. last commit

When Things Go Wrong

Everyone makes mistakes. Git gives you tools to recover:

  • Wrong commit message? → git commit --amend
  • Committed too early? → git reset --soft HEAD~1
  • Need to start over? → git reset --hard HEAD~1
  • Work in progress? → git stash to save it for later

In the next exercises, you'll practice each of these tools.