Basics: from file to commit · Lesson 3 of 15
Read history and differences
Use log, show, diff and diff --staged before judging or committing changes.
git log --oneline summarizes history, git show explains a commit, and git diff asks what changed but is not staged. git diff --staged reviews the proposed next snapshot.
| Command | What it compares |
|---|---|
git diff | working tree ↔ staging |
git diff --staged | staging ↔ last commit |
git show | A commit and its patch |
git log --oneline | History summary |
git init -q -b main echo "red" > colors.txt git add colors.txt git commit -q -m "Start colors" echo "blue" >> colors.txt git diff git add colors.txt git diff --staged
A - line belongs to the old version and a + line to the new one; the markers are not file content. Compare branches or commits with git diff ref1 ref2.
Quick question
After git add, which command shows the next commit's content?
Exercise
Make two commits named Chapter one and Chapter two, then print subjects newest first.
Chapter two Chapter one
git init -q -b main echo "one" > story.txt git add story.txt git commit -q -m "Chapter one" git log --format=%s
Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.