Viewing History

Every commit you make sticks around forever (unless you go out of your way to remove it). Git gives you a few commands to look back through that history.

git log

The full history of the current branch, newest first:

$ terminal
git log
Terminal output
commit 7c3e8a1f2b9d4e5f6a7b8c9d0e1f2a3b4c5d6e7f
Author: Ava Chen <ava@example.com>
Date:   Tue Sep 2 14:12:03 2026 -0700

    Add contact page

commit 4a1f9c2d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b
Author: Ava Chen <ava@example.com>
Date:   Mon Sep 1 09:40:51 2026 -0700

    Add homepage markup

Each entry shows the full commit ID, who made it, when, and the message. When history gets long, this full view gets noisy fast.

A more readable view

--oneline compresses each commit to a single line, which is far more useful for scanning recent activity:

$ terminal
git log --oneline
Terminal output
7c3e8a1 Add contact page
4a1f9c2 Add homepage markup

The short 7-character code at the start of each line is the beginning of that commit's ID — enough to uniquely identify it in most projects, and what you'll use with commands like git checkout or git revert when you need to point at a specific commit.

git diff

While git log shows you commits, git diff shows you the actual line-by-line changes that haven't been committed yet:

$ terminal
git diff
Terminal output
diff --git a/index.html b/index.html
index 3f2a1b0..9d8c7e6 100644
--- a/index.html
+++ b/index.html
@@ -4,6 +4,6 @@
-  <h1>Welcome</h1>
+  <h1>Welcome to my site</h1>

Lines starting with - were removed, lines starting with + were added. This is invaluable right before you commit — a quick git diff lets you double-check exactly what you're about to save, which catches a surprising number of accidental leftover debug lines and stray edits.

Note: git diff on its own only shows unstaged changes. Once you've run git add, use git diff --staged to see what's waiting in the staging area.