Viewing History
git log — Browse Your Commits
Once you have commits, you can view them all:
git log
Each entry shows the commit hash (a unique ID), author, date, and message. Press q to quit the pager in a real terminal.
Compact View
For a cleaner one-line summary:
git log --oneline
This is the format most developers use day-to-day — easier to scan a long history.
git diff — See What Changed
git diff shows the difference between your current working files and the last commit:
git diff
Lines starting with + are additions (green), lines starting with - are removals (red).
Staged Changes
To see what's staged (already in the next commit):
git diff --staged
Tip: Run
git diff before staging and git diff --staged after staging. This lets you double-check your changes before committing.
git show — Inspect a Single Commit
To see exactly what a specific commit changed:
git show # shows the most recent commit git show a1b2c3d # shows a specific commit by its short hash
The hash comes from git log --oneline. You only need the first 7 characters.
Reading a Diff
diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
# My Project
-This is version 1.
+This is version 2.
+Added a new line.
The @@ line tells you where in the file the change is. Lines with no prefix are context (unchanged).
Your Challenges
Run
git log to view the commit history
Run
git log --oneline for the compact view
Edit a file (
echo change > file.txt), then run git diff
Run
git show to inspect the most recent commit
student@git-mastery: ~/my-project