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 timelinegit diff— Compare file versions between statesgit stash— Temporarily shelve uncommitted workgit 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 areagit diff --staged— Staging area vs. last commitgit 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 stashto save it for later
In the next exercises, you'll practice each of these tools.