git log—displays your repository's commit history with author, timestamp, and message details. It's essential for tracking changes, reviewing past work, and understanding project evolution. Git log is completely safe and one of the most frequently used commands in version control workflows.
Every developer faces the same challenge: understanding what happened in a project weeks or months ago. Who made that critical change? When was the bug introduced? Which commit broke the build? Without proper tools to inspect your repository's history, you're flying blind.
The git history command—technically git log—is your answer. It's not flashy or complicated, but it's absolutely essential. Whether you're debugging a production issue, reviewing a teammate's work, or preparing for a code audit, mastering git history commands transforms you from a developer who just pushes code into one who truly understands their project's evolution.
This guide walks you through everything: from basic syntax to advanced filtering, real-world examples, and troubleshooting tips. By the end, you'll be able to extract exactly the information you need from your repository in seconds.
git log --oneline --graph --all combination is used by over 80% of professional development teams to get a quick overview of branch relationships and recent activity. Learning this single command saves hours of debugging time weekly.
git log is Git's primary command for exploring your repository's commit history. It displays a chronological record of all changes made to your project, showing:
Think of git log as a forensic tool for your codebase. It answers questions like "When was this file last modified?" "Who introduced this bug?" and "What changes happened between two releases?"
Unlike other Git commands that modify your repository, git log is completely read-only. You can explore your entire history without risk of accidentally deleting or changing anything.
The simplest form of the command is:
git log
This displays commits in reverse chronological order (newest first), showing full details. Each commit entry typically looks like:
commit abc1234def5678901234567890abcdef1234567
Author: Sarah Chen <[email protected]>
Date: Wed Aug 21 14:32:15 2026 -0500
Fix validation bug in user authentication
- Added email format validation
- Updated error messages for clarity
- Added unit tests for edge cases
To exit the log view in your terminal, press q. Navigate with arrow keys or Page Up/Page Down.
However, full logs can be overwhelming for large projects with thousands of commits. That's where flags come in to refine and filter the output.
git log --oneline
Output:
a7f8e9c (HEAD -> main) Update README with installation steps
f2d1c3b Add dark mode toggle to settings panel
e8c7b2a Refactor database connection pooling
d4a6f1e Fix memory leak in image processing
c9e2a5b Initial project setup
This shows commit hash and message on a single line, perfect for quick scanning. The (HEAD -> main) indicates your current position in the repository.
git log -5
Shows only the last 5 commits. Replace 5 with any number. Useful for reviewing recent work without scrolling through years of history.
git log -p -2
The -p flag shows the actual code differences (diff) for each commit. The -2 limits output to the last 2 commits. Expect verbose output, but you'll see exactly what changed line-by-line.
git log --author="Sarah Chen"
Shows only commits made by Sarah Chen. Useful for code reviews, understanding a team member's contributions, or finding who touched specific code.
git log --since="1 week ago" --until="now"
Shows all commits made in the past 7 days. You can also use:
--since="2 weeks ago"--since="2026-08-01"--since="10 days ago"Perfect for generating weekly status reports or tracking sprint progress.
| Flag | Purpose | Example Usage |
|---|---|---|
--oneline |
Compact format: hash and message on one line | git log --oneline |
-n or --max-count |
Limit output to N commits | git log -n 10 |
-p or --patch |
Show full code changes (diffs) for each commit | git log -p |
--stat |
Show file statistics (files changed, insertions, deletions) | git log --stat |
--name-only |
Show only filenames modified in each commit | git log --name-only |
--author |
Filter by author name (supports regex) | git log --author="John" |
--committer |
Filter by committer name (different from author in some workflows) | git log --committer="Sarah" |
--since |
Show commits after a specific date or time period | git log --since="2026-08-01" |
--until |
Show commits before a specific date or time period | git log --until="2026-08-23" |
--grep |
Search commit messages by keyword (case-sensitive by default) | git log --grep="fix" -i |
-S |
Find commits that added or removed specific code/text | git log -S "function_name" |
--graph |
Display branch and merge history as ASCII graph | git log --graph --oneline |
--all |
Include all branches, not just current branch | git log --all --oneline |
--decorate |
Show branch and tag labels on commits | git log --decorate |
--reverse |
Show commits in reverse order (oldest first) | git log --reverse |
git log --grep="payment" -i
The -i flag makes the search case-insensitive. This finds all commits with "payment" in the message, regardless of capitalization. Useful for tracking feature implementations or bug fixes by topic.
git blame path/to/file.js
While technically git blame rather than git log, this command shows who modified each line and when. Invaluable for understanding complex code sections.
git log -S "validateEmail" --oneline
Shows every commit that added or removed the text "validateEmail" anywhere in the codebase. Perfect for tracking when a function was introduced or removed.
git log --author="Sarah\|John" --oneline
The pipe character (|) acts as OR in regex. This shows commits by either Sarah OR John. Most useful for team analysis or understanding cross-functional contributions.
git log --since="2026-08-01" --until="2026-08-15" --oneline
Shows all commits made during a specific period. Essential for sprint reviews, monthly reports, or investigating when a regression occurred.
git log origin/production --oneline
Shows commits on the production branch specifically, not your local branch. Replace origin/production with any branch name.
git log main..HEAD --oneline
Shows commits on your current branch that don't exist on main. The syntax branch1..branch2 means "commits in branch2 but not in branch1." Critical before submitting pull requests to see exactly what you've changed.
git log --merges --oneline
Shows only commits that represent merge operations. Useful for understanding release timelines and integration history.
git log --no-merges --oneline
Shows all regular commits, skipping merges. Gives a cleaner view of actual feature and bug fix work.
git log --oneline --graph --all --decorate
Output example:
* a7f8e9c (HEAD -> main) Update README
|\
| * f2d1c3b (feature/dark-mode) Add dark mode toggle
| * e8c7b2a Refactor database pooling
|/
* d4a6f1e (origin/main) Fix memory leak
* c9e2a5b Initial setup
This visualization shows:
HEAD -> mainorigin/mainfeature/dark-modePro tip: Create an alias for this command in your .gitconfig:
git config --global alias.hist "log --oneline --graph --all --decorate"
Now simply type git hist for instant visualization.
git log --pretty=format:"%h - %an, %ar : %s"
This shows a custom format with: commit hash, author name, relative time, and subject. You can customize %h, %an, %ar, %s, and dozens of other placeholders for exactly the data you need.
Instead of memorizing command syntax, you can use the Git Graph extension in VSCode:
This provides point-and-click access to all git log features without terminal commands.
For remote repositories, GitHub provides a web-based history viewer:
This is perfect for non-technical team members or quick reviews without local setup.
In massive repositories with hundreds of thousands of commits, git log can be slow. Follow these strategies:
git log --oneline -50
Always specify a reasonable limit like -50 or -100 instead of loading all history.
git log --oneline --no-merges -- src/
The -- and path specification limits history to a specific directory, reducing output significantly.
git clone --depth=1 https://github.com/user/repo.git
For initial setup on large repos, clone only recent history. Later, use git fetch --unshallow if you need full history.
When performance matters:
--oneline instead of -p to skip computing diffs--all-match with multiple --grep filters to narrow results quickly--grep with -p on large repositoriesProblem: git log --author="John" returns nothing.
Solution: Author filters are case-sensitive and match partial names. Try:
git log --author="john" -i
The -i flag enables case-insensitive matching. Also verify the author name is spelled correctly with git log --oneline | head to see recent commits.
Problem: git log only shows your current branch history.
Solution: Add the --all flag:
git log --all --oneline
This includes all branches, making sure you see the complete repository history.
Problem: git log --grep="fix" returns no results despite knowing the commit exists.
Solution: Try case-insensitive search:
git log --grep="fix" -i --oneline
Also verify the search term appears in the commit message subject, not just in the body, unless you use additional flags.
Problem: git log is freezing on a large repository.
Solution: Always use limiting flags:
git log -50 --oneline --no-merges
Never run bare git log on production repositories with years of history. Always specify -n, --since, or directory filters.
git log --oneline --decorate with grep filters to reduce output to exactly what you need, cutting search time from minutes to seconds in enterprise codebases.
git log shows your project's commit history. git reflog shows your local Git reference history—every action you've taken, including checkouts and resets. Use git reflog to recover accidentally deleted commits or branches.
Use:
git log -p path/to/file.js
This shows only commits that modified that specific file, with full diffs.
Yes, use shell redirection:
git log --oneline > history.txt
This saves the output to history.txt for documentation or analysis.
On GitHub, navigate to the pull request and click the "Commits" tab. In the terminal, use:
git log --oneline branch-name --not main
This shows commits unique to the feature branch.
Completely safe. git log is read-only and cannot modify your repository, remote, or anyone else's work. Use it freely in any situation.
Your repository has a long history. Use filtering flags to reduce output:
git log -n 50 --oneline --no-merges
This limits to the last 50 non-merge commits, giving a cleaner view.
"Understanding your repository's history through proper use of git log transforms code review and debugging from guesswork into forensic analysis. The tool exists for a reason—master it and you'll identify production issues in minutes instead of hours."
— Best practices in version control workflows, recognized across professional development teams