Inspecting Commit History with git log and Formatting Flags
Inspecting Commit History with git log and Formatting Flags
As software evolves over months and years, inspecting historical commits becomes crucial for tracking features, conducting post-mortems on bugs, and reviewing peer contributions. The git log command is Git's primary time machine.
1. Basic History Inspection: git log
Executing git log lists the commits made in that repository in reverse chronological order (newest commit first):
Standard Output Format:
less.
- Press Spacebar to scroll down one page.
- Press b to scroll up.
- Press q to quit and return to the command prompt.2. Essential Power Flags for git log
A. Compact Single-Line View (--oneline)
Condenses each commit into its short 7-character hash and commit title:
Output:
B. Limit Output Count (-n <number>)
View only the last $N$ commits:
C. Show Changed Files and Stats (--stat)
Displays the files modified, number of lines inserted (+), and deleted (-):
D. Show Full Line-by-Line Code Patches (-p)
Shows the actual line diff introduced by each commit:
3. Visual Branch Graph (--graph --oneline --all)
When multiple developers are branching and merging, visualizing the branch tree topology directly in your terminal is invaluable:
Terminal Output:
Pro Tip: Create an Alias for Visual Log
Save this command permanently as an alias:
4. Filtering History
Git lets you filter commit history with precision:
Practice Quiz
git log?git log into a clean single-line representation per commit?src/db.js?Comparing Changes with git diff (Working Tree vs Staged vs HEAD)
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.