Viewing History
9.1 Basic Commit History
The simplest command to view history:
This shows:
• Commit hash
• Author
• Date
• Commit message
Example output:
Use this to understand the chronological sequence of project changes.
1git logThis shows:
• Commit hash
• Author
• Date
• Commit message
Example output:
1commit a1c3f9d
2Author: Sarah Lee <sarah@example.com>
3Date: Tue Nov 6 16:22:10 2025
4
5 Add user authentication logicUse this to understand the chronological sequence of project changes.
9.2 Compact, Readable Logs
One-line version:
Gives something like:This is great for quick scanning.
Show only last N commits:
1git log --onelineGives something like:
1a1c3f9d Add user authentication logic
265ab29c Update README
348cfe19 Fix typo in login pageShow only last N commits:
1git log -5 --oneline9.3 Visual Graph of Branches
To understand how branches diverged and merged:
This displays a tree-like view:
Helpful for navigating complex project histories.
1git log --oneline --graph --decorate --allThis displays a tree-like view:
1* a1c3f9d (HEAD -> main) Add user authentication logic
2|| * 48cfe19 Feature: add user avatar upload
3* | 65ab29c Update README
4|/
5* 39fa114 Initial commitHelpful for navigating complex project histories.
9.4 Filtering History (Search & Narrowing)
Find commits by author:
Search for text in commit messages:
Show commits affecting a specific file:
Limit by date:
Filtering helps you quickly locate relevant changes.
1git log --author="Sarah"Search for text in commit messages:
1git log --grep="authentication"Show commits affecting a specific file:
1git log --oneline -- <path/to/file>Limit by date:
1git log --since="2 weeks ago"
2git log --until="2023-01-01"Filtering helps you quickly locate relevant changes.
9.5 Inspecting Changes in Commits
Show what changed in each commit:
Show diffs for only one commit:
Example:
This reveals:
• Added lines
• Removed lines
• Updated code segments
This is essential for debugging or code review.
1git log -pShow diffs for only one commit:
1git show <commit-hash>Example:
1git show a1c3f9dThis reveals:
• Added lines
• Removed lines
• Updated code segments
This is essential for debugging or code review.
9.6 Browsing History with Blame
git blame lets you see who last changed each line of a file:
You get output like:
Use this to trace:
• When a bug was introduced
• Who last edited a specific line
• The context around a change
1git blame file.jsYou get output like:
1a1c3f9d (Sarah Lee 2025-11-06) function login() {
248cfe19 (Dev Patel 2025-11-04) validateUser(input);Use this to trace:
• When a bug was introduced
• Who last edited a specific line
• The context around a change
9.7 Viewing History Without Clutter
Exclude merge commits:
Customize the output format:
Custom formats help you generate clean reports or summaries.
1git log --no-merges --onelineCustomize the output format:
1git log --pretty=format:"%h - %an : %s"Custom formats help you generate clean reports or summaries.
9.8 Key Takeaways
• git log is the main tool for exploring commit history.
• Use --online, --graph, and --decorate for simplified and visual history.
• Filtering options like --author, --grep, --since, and file-specific logs help pinpoint changes.
• git show and git log -p reveal actual code modifications.
• git blame identifies line-by-line authorship for deeper investigation.
• Git's history tools make it easy to understand, audit, and navigate your project's evolution.
• Use --online, --graph, and --decorate for simplified and visual history.
• Filtering options like --author, --grep, --since, and file-specific logs help pinpoint changes.
• git show and git log -p reveal actual code modifications.
• git blame identifies line-by-line authorship for deeper investigation.
• Git's history tools make it easy to understand, audit, and navigate your project's evolution.