What is git log in Git? – A Simple Guide with Examples and FAQ
What is git log?
git log is a command used to view the commit history of your project in Git. It helps you track:
- Who made each commit
- When it was made
- What the commit message says
- The commit hash (unique ID)
Think of it as your Git journal — recording everything that’s happened in your project’s history.
Why Do We Use git log?
We use git log to:
View complete history of the repository
Search for specific changes, keywords, or authors
Understand how the code evolved
Debug issues by identifying when changes were introduced
Significance of git log
| Feature | Why It’s Important |
|---|---|
| Full history | Tracks all changes over time for audit/review |
| Author visibility | Shows who made what changes |
| Powerful filters | Search by keyword, author, file, or date |
| Debug-friendly | Helps identify when bugs or regressions were introduced |
Common git log Commands with Examples
1. View Full Commit History
git log
Displays:
- Commit hash
- Author name & email
- Date of commit
- Commit message
2. Show the Last N Commits
git log -2
Change the number to fetch more:
git log -5 # Last 5 commits
3. One-Line Summary View
git log --oneline
Output Example:
a1b2c3d Fixed login bug
d4e5f6g Added new feature
Great for a quick overview of commit history!
You can also limit the number of entries:
git log --oneline -3
4. Search Commits by Keyword
git log --grep="login"
This searches commit messages for the word “login.”
You can combine it with --oneline:
git log --oneline --grep="homepage"
5. View Commits That Modified a Specific File
git log -- filename.txt
This shows only commits that actually changed that file — very useful when debugging file-level issues.
If you want to search for file names mentioned in messages (not changes), use:
git log --grep="filename"
Summary – Git Log
git log is one of the most powerful and frequently used Git tools for inspecting your project’s history.
Key Takeaways:
- View full or filtered commit history with
git log - Use
--oneline,--author, or--grepfor focused searches - Investigate changes made to specific files
- Use
git log -pto inspect diffs for each commit
Real-World Relevance:
- Crucial for teams collaborating on large codebases
- Essential for debugging and tracking down regressions
- Supports auditing for security and compliance
Practice combining options to master the true power of Git history exploration!
FAQ Frequently Asked Questions — Git Log
How do I see commits by a specific author?
git log --author="Alice"
This shows all commits made by someone named Alice.
Can I view the actual changes in each commit?
git log -p
Yes! This shows the diffs — what was added, removed, or modified in each commit.
What’s the difference between --grep and -- filename?
--grep="text"→ filters commit messages-- filename.txt→ filters commits that changed a file
Can I combine filters like author and message?
git log --oneline --author="Bob" --grep="fix"
Absolutely! Combine flags to drill into specific commits fast.
How do I exit the git log screen?
Just press:
q
This exits the default pager (less).
How do I find a commit by its message?
git log --grep="message-text"
Helps you quickly find commits related to a particular feature or bug fix.
Share Now :
