The git log command displays the commit history of a Git repository, showing each commit’s hash, author, date, and message. You run it inside a repository to see a reverse-chronological list of commits, and you can customize its output with flags to show patches, graphs, or specific branches.
What Git Log Shows by Default
Running git log with no arguments prints a list of commits starting from the current branch’s HEAD. Each entry includes:
- Commit hash – a 40-character SHA-1 checksum (or shorter with
--abbrev-commit). - Author – the name and email configured in Git.
- Date – the commit timestamp.
- Commit message – the first line (subject) by default.
For example, git log might output:
commit 9fceb02d0b2c1a4c5e6f7a8b9c0d1e2f3a4b5c6d
Author: Jane Doe <jane@example.com>
Date: Tue Jan 14 10:30:00 2025 +0000
Fix login bug on mobile
The output is paginated (usually with less), so press q to quit, Space to page down, and / to search.
Common Flags and Options
Git log becomes powerful when you add flags that filter or change the output format. Here are the most useful ones:
--oneline– shows each commit on a single line with a shortened hash and subject. Ideal for a quick overview.--graph– draws an ASCII graph of branch and merge history, often combined with--onelineand--all.-por--patch– shows the full diff (changes) introduced by each commit.--stat– shows a summary of files changed and the number of insertions/deletions per commit.--author="name"– filters commits by author (supports regex).--since=2024-01-01and--until=2024-12-31– filters by date range.-n 5or-5– limits output to the last 5 commits.--grep="pattern"– searches commit messages for a pattern.--all– shows commits from all branches (not just the current one).--follow -- file.txt– shows history of a single file, including renames.
These flags can be combined, e.g., git log --oneline --graph --all gives a compact view of the entire repository’s branching structure.
Filtering by Branch and Range
You can restrict git log to a specific branch or commit range. For example:
git log main– shows commits reachable from themainbranch.git log main..feature– shows commits infeaturethat are not inmain(i.e., the unique work on that branch).git log feature...main– shows commits reachable from either branch but not both (symmetric difference).git log HEAD~5..HEAD– shows the last 5 commits on the current branch.
These range syntaxes are also used by other Git commands like git diff and git rebase, so learning them helps across the tool.
Viewing a Specific Commit
To inspect a single commit in detail, use git show <commit-hash> instead of git log. It displays the commit metadata, the diff, and the message. If you only want the diff of the most recent commit, git show HEAD works. For a quick summary of a commit, git show --stat <hash> is handy.
Common Mistakes and Pitfalls
New users often confuse git log with git status or git diff. Remember: git status shows the working tree and staging area, git diff shows uncommitted changes, and git log shows committed history. Another common issue is forgetting that git log only shows commits reachable from the current branch unless you use --all. If you just committed to a different branch, you won’t see it until you switch or use --all.
Also, the default output is long; don’t try to scroll through hundreds of commits manually. Use --oneline and filters to narrow down what you need.
Comparing Git Log with Other Tools
While git log is the command-line workhorse, many developers use GUI tools for visual exploration. Tools like GitKraken, SourceTree, or the built-in Git graph in VS Code provide a graphical representation of the same history. These are useful for seeing branch topology at a glance, but they rely on the same underlying data that git log reads. For scripting or quick terminal checks, git log remains the fastest and most flexible option.
Frequently Asked Questions
How do I exit git log?
Press q. Git log uses a pager (usually less), and q quits it. If you want to disable the pager for a single command, use git --no-pager log.
How do I see the date of the last commit?
Run git log -1 --format="%ci" to get the committer date in ISO format. The %ci placeholder prints the committer date, and -1 limits to one commit.
How do I search for a commit by message?
Use git log --grep="search term". It searches the commit message subject and body. Add -i for case-insensitive matching.
Why does git log show commits I didn’t make?
If you pulled or merged, you’ll see commits from other authors. Also, if you’re on a branch that tracks a remote, git log includes all commits reachable from that branch, including those from collaborators. Use --author="yourname" to filter.
What is the difference between git log and git reflog?
git log shows the commit graph (the DAG of commits). git reflog shows the history of where your HEAD and branch references have pointed, including commits that are no longer referenced. Reflog is useful for recovering lost commits.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Server Repair Fails: Fix Restart Loops
- Plane Crazy Summer Event Schedule & Dates3 tier
- How to Choose a Secure IMAP Email Client
- Tower Defense RNG Codes: Active List & How to Redeem
- RCS Chats On or Off in Google Messages
- How to Choose a Phone That Supports VoLTE on Your Carrier