Git Log Explained: 15 Useful Commands and Pretty Formats
git log shows your project history, and with the right options it answers almost any question: who changed this, when, why, and on which branch. Learn the default output, oneline and graph views, filtering by author, date, message and code, file history, commit ranges and custom pretty formats, all run in a real repository.
- git log lists commits newest first;
--oneline --graph --allis the best single overview of a repository. - Filter with
--author,--since/--until,--grepfor messages and-Sfor code that was added or removed. git log -- pathshows one file’s history;--statand-pshow what each commit changed.A..Bmeans “commits in B that are not in A”, which can include commits from merged branches, as our range test showed.
When a bug appears, the first question is “what changed?” and the second is “why?”. The answers live in your commit history, and git log is how you read it. Its default output is verbose and hard to scan, but a handful of options turn it into a precise search tool for authors, dates, messages, files and even individual lines of code.
We ran every command in a throwaway repository with Git 2.56 and show the real output. The repository uses placeholder authors, Demo and Sample Dev, with example.com addresses and fixed dates, so no real identities appear. New to Git? Start with our Git commands cheat sheet.
What is git log?
git log walks the commit graph backwards from a starting point (by default your current HEAD) and prints each commit it reaches. Every option either changes which commits are shown (filters and ranges) or how they are shown (formats, stats and patches). It never changes anything, so experiment freely.
Our test repository
Six commits over two weeks: four on main, one on a feature branch, and a merge commit that brought the feature back, tagged v1.0. Two authors contributed.
1. The default output
git log -1
commit 258307068a750a7b84dd1c6de205a1ed1f24bce1
Merge: acbe826 f863bbd
Author: Demo <demo@example.com>
Date: Wed Nov 18 14:00:00 2026 +0000
Merge branch feature
Each entry shows the full 40-character hash, the parents for a merge commit, the author with email, the author date and the full message. It is complete but takes five or more lines per commit, which is why most people reach for a compact format. Press q to leave the pager when output is long.
2. One line per commit
git log --oneline
2583070 Merge branch feature
acbe826 Fix rounding bug in cart
f863bbd Add discount
a460fca Docs: add README
c31aad2 Add cart total
eca4e21 Initial commit
--oneline shows the short hash and the subject line only. It is the quickest way to see recent history, and a good reason to write clear, specific commit subjects.
3. The branch graph
git log --oneline --graph --all --decorate
* 2583070 (HEAD -> main, tag: v1.0) Merge branch feature
|\
| * f863bbd (feature) Add discount
* | acbe826 Fix rounding bug in cart
|/
* a460fca Docs: add README
* c31aad2 Add cart total
* eca4e21 Initial commit
--graph draws the branch structure in text, --all includes every branch instead of just the current one, and --decorate labels commits with branches and tags. You can see exactly where feature split off, the parallel work on main, and the merge. Many developers save this as an alias: git config --global alias.lg "log --oneline --graph --all --decorate". Our merge vs rebase guide shows how history looks with each strategy.
4. Limit the number of commits
git log -n 2 --oneline
2583070 Merge branch feature
acbe826 Fix rounding bug in cart
-n 2, or simply -2, shows the two most recent commits. Combine it with any filter to see only the latest matches.
5. Filter by author
git log --author="Sample Dev" --oneline
f863bbd Add discount
a460fca Docs: add README
--author matches a pattern against the name and email, so a partial name or an email domain works too. --committer does the same for the person who applied the commit, which differs after rebases and cherry-picks.
6. Filter by date
git log --since="2026-11-11" --until="2026-11-16" --oneline
acbe826 Fix rounding bug in cart
f863bbd Add discount
--since and --until (aliases --after and --before) accept exact dates or phrases such as "2 weeks ago" or "yesterday". They filter on the committer date, which is usually what you want for “what landed this week?”.
7. Search commit messages
git log --grep="bug" -i --oneline
acbe826 Fix rounding bug in cart
--grep searches commit messages, and -i makes it case-insensitive. It is the fastest way to find the commit that mentions a ticket number such as --grep="SHOP-123", one more reason to include ticket IDs in messages.
8. Find when code was added or removed
git log -S"d" --oneline -- discount.py
f863bbd Add discount
The “pickaxe” option -S finds commits that changed the number of occurrences of a string, meaning commits that added or removed it. Searching for a function name tells you when it was introduced or deleted, even if no message mentions it. -G takes a regular expression and also matches lines that merely changed. For “which commit broke this?”, combine with git bisect.
9. History of one file
git log --oneline -- README.md
a460fca Docs: add README
Put the path after -- to show only commits that touched it. Add --follow for a single file to keep tracking it across renames. For line-by-line authorship, git blame is the companion command.
10 and 11. Stats and full patches
git log -1 --stat --format="%h %s" HEAD~1
acbe826 Fix rounding bug in cart
app.py | 1 +
1 file changed, 1 insertion(+)
git log -1 -p --format="%h %s" HEAD~2
a460fca Docs: add README
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+x
--stat summarises changed files and line counts per commit; -p (patch) shows the full diff. Our git diff guide explains how to read that patch output. HEAD~1 means “one commit before HEAD” on the first-parent line.
12. Custom pretty formats
git log --pretty=format:"%h | %an | %ad | %s" --date=short
2583070 | Demo | 2026-11-18 | Merge branch feature
acbe826 | Demo | 2026-11-15 | Fix rounding bug in cart
f863bbd | Sample Dev | 2026-11-12 | Add discount
a460fca | Sample Dev | 2026-11-10 | Docs: add README
c31aad2 | Demo | 2026-11-05 | Add cart total
eca4e21 | Demo | 2026-11-01 | Initial commit
| Placeholder | Meaning |
|---|---|
%H / %h |
Full / short commit hash |
%an / %ae |
Author name / email |
%ad / %ar |
Author date / relative date (“3 days ago”) |
%s / %b |
Subject / body |
%d |
Branch and tag names |
%n |
Newline |
Custom formats are perfect for release notes, CSV exports and scripts. --date=short gives ISO dates, and --date=iso includes times. Use tformat: instead of format: if you want a newline after the last entry too.
Tip: generate quick release notes between two tags with git log v1.0..v1.1 --pretty=format:"- %s (%h)" --no-merges.
13. Showing or hiding merge commits
git log --no-merges --oneline | wc -l
5
git log --merges --oneline
2583070 Merge branch feature
--no-merges hides merge commits, useful for release notes; --merges shows only them, useful for seeing which branches landed. --first-parent follows only the main line of history and skips the commits inside merged branches.
14. Commit ranges
git log --oneline main~2..main
2583070 Merge branch feature
acbe826 Fix rounding bug in cart
f863bbd Add discount
A..B means “commits reachable from B but not from A”. We asked for the last two steps of main, yet got three commits: the merge brought in f863bbd from the feature branch, which is reachable from main but not from main~2. Ranges answer “what is on my branch that is not on main?” with git log main..feature, and A...B (three dots) shows commits on either side but not both. This is also how you check what a rebase or cherry-pick will touch.
15. Summaries and counts
git shortlog -sn --all
4 Demo
2 Sample Dev
git rev-list --count HEAD
6
git shortlog -sn counts commits per author, a quick view of who has worked on a codebase. git rev-list --count returns the number of commits reachable from a reference, handy for build numbers.
Git log cheat sheet: 15 commands
| # | Goal | Command |
|---|---|---|
| 1 | Full details | git log |
| 2 | Compact list | git log --oneline |
| 3 | Branch graph | git log --oneline --graph --all --decorate |
| 4 | Last N commits | git log -n 5 |
| 5 | By author | git log --author="name" |
| 6 | By date | git log --since="2 weeks ago" |
| 7 | By message | git log --grep="SHOP-123" -i |
| 8 | By code change | git log -S"function_name" |
| 9 | One file | git log --follow -- path |
| 10 | Files per commit | git log --stat |
| 11 | Full diffs | git log -p |
| 12 | Custom format | git log --pretty=format:"%h %an %s" |
| 13 | Skip merges | git log --no-merges |
| 14 | Branch difference | git log main..feature |
| 15 | Commits per author | git shortlog -sn |
Final thoughts
git log becomes a precise search engine once you know its options. Start with --oneline --graph --all for the overview, filter by author, date, message or code with --author, --since, --grep and -S, narrow to a file with -- path, and shape the output with pretty formats for reports. Combined with good commit messages and tags for releases, your history becomes documentation you can actually query.
Frequently asked questions
How do I see the commit history in Git?
Run git log to list commits from newest to oldest. Add the oneline option for one line per commit, or the graph and all options to see branches and merges.
How do I see the history of a single file?
Run git log followed by two dashes and the file path. Add the follow option to keep tracking the file across renames, and use git blame for line by line authorship.
How do I search commits by message in Git?
Use git log with the grep option and a search term, adding the i flag for case insensitive matching. To find commits that added or removed some code, use the S option instead.
How do I show commits by one author?
Use git log with the author option and part of the name or email. It accepts patterns, so an email domain or a first name is often enough.
What does main..feature mean in git log?
It lists commits that are reachable from feature but not from main, which is the work on the feature branch that main does not have yet.
Keep learning
Need help with testing, WordPress or SEO?
We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.