Read history with log and show
Read history with log and show
A repository becomes useful when you can answer 'what changed?', 'when?', and 'which branch contains it?' without opening old folder copies.
What you’ll learn
- Read compact commit history.
- Inspect one commit.
- Use relative commit references.
Navigate the commit graph
log
See commit sequence and branch pointers.
history graphreference
Choose a hash, branch or relative name.
HEAD~1show
Inspect the selected commit.
metadata + patch
History is a graph, not just a list
git log walks commit history. Formatting options can show a compact branch graph, while git show inspects one commit in detail.
Commit hashes are identifiers. You usually type a sufficiently unique short prefix rather than the full hash. Relative names such as HEAD~1 mean 'the first parent of HEAD.'
Inspect the graph and a file's history
Run this in a disposable practice repository unless the lesson explicitly says otherwise.
git log --oneline --decorate --graph --all
git show HEAD
git log -- notes.txtThe graph view is especially useful after branches and merges. git log -- notes.txt limits history to commits that affect that path.
Practice: Log and show
Your task: Create two commits, then use git show HEAD~1 to inspect the older one. Find its message and changed files.
Common pitfall to avoid
A commit hash can change when history is rewritten, such as after rebase or amend. Do not treat a rewritten local hash as a permanent public identifier.
Check your understanding
Log and show: what to remember
Read history with log and show is complete when you can explain the state being changed before you run the command, not merely repeat the syntax.
Read further: official supporting documentation.
Reaching the recap and completing the quizzes are separate milestones.