1. Home
  2. Blog
  3. DevOps

DevOps

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.

9 min read
Git log explained: 15 useful commands and pretty formats

Key takeaways

  • git log lists commits newest first; --oneline --graph --all is the best single overview of a repository.
  • Filter with --author, --since/--until, --grep for messages and -S for code that was added or removed.
  • git log -- path shows one file’s history; --stat and -p show what each commit changed.
  • A..B means “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

Work with Stack Quora

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.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Artificial Intelligence

Linear Regression in Python: Least Squares From Scratch, With R Squared

Linear regression in Python from scratch: closed form, NumPy least squares and gradient descent, R squared, RMSE, outliers and curved…

Read article →
Software Development

301 vs 302 Redirect: Differences, SEO Impact, 307 and 308

301 vs 302 redirect: the differences, SEO impact, 307 and 308, method changes, redirect chains and loops, all tested on…

Read article →
DevOps

Git Remote Explained: Add, Set-URL, Rename, Remove and Push URLs

Git remote explained: add, set-url, separate push URLs, rename, remove and prune, plus how to avoid leaking tokens in remote…

Read article →
Test Automation

Pytest Mock: mocker.patch, spy, side_effect and autospec Explained

Pytest mock explained: mocker.patch, return_value, side_effect, spy, autospec and PropertyMock, with tested examples for APIs, clocks and retries.

Read article →
Software Testing

System Testing Explained: Types, Process and a Real End-to-End Example

System testing explained: types, entry and exit criteria, the process, and a real end-to-end test suite run against a small…

Read article →
Databases & SQL

SQL Random Rows: How to Select Random Rows Fast and Fairly

SQL random rows: how to select random rows fast and fairly, timing ORDER BY RANDOM, offsets and ID jumps, and…

Read article →
Databases & SQL

SQL Median: 4 Ways to Calculate the Median, With Tested Queries

SQL median explained: four tested ways to calculate the median, including percentile functions, window ranks, offsets and per group medians.

Read article →
Software Development

JavaScript Regex Explained: Patterns, Flags, Groups and Pitfalls

JavaScript regex explained: literals, flags, groups, named groups, lookarounds, matchAll, replace and the catastrophic backtracking trap, tested in Node.

Read article →
Software Development

Python property: Getters, Setters, Validation and cached_property

Python property explained: getters, setters, deleters, validation, read-only and computed attributes, and cached_property, with tested code.

Read article →
Software Development

Python Enum Explained: auto, IntEnum, StrEnum, Flag and Best Practices

Python enum explained with tested examples: Enum, auto, IntEnum, StrEnum, Flag, aliases, unique, JSON serialisation and match statements.

Read article →
Artificial Intelligence

Naive Bayes Classifier Explained: Build a Spam Filter in Python

Naive Bayes classifier explained by building a spam filter in Python: Bayes rule, the naive assumption, Laplace smoothing, log probabilities…

Read article →
Software Development

401 vs 403: Unauthorized vs Forbidden, and When to Use Each

401 vs 403 explained: authentication vs authorization, the WWW-Authenticate header, when to return 404 instead, client reactions and a tested…

Read article →
DevOps

Git Branch Explained: Create, Switch, Rename, Delete and Recover

Git branch explained with tested commands: list, create, switch, rename, delete, merged checks, recovering deleted branches, remote tracking and naming.

Read article →
Test Automation

Pytest raises: Testing Exceptions, match and excinfo

Pytest raises explained with tested examples: match regexes, excinfo, custom and chained exceptions, parametrized error cases, pytest.warns and common mistakes.

Read article →
Software Testing

Non Functional Testing: Types, Metrics and a Real Load Test

Non functional testing explained: 10 key types, measurable requirements, latency percentiles and what a small real load test revealed about…

Read article →
Databases & SQL

SQL ROUND Function: Decimals, Ties, CEIL, FLOOR and Money

SQL ROUND explained with tested queries: decimals, tie rules, the 2.675 float trap, negative digits, CEIL, FLOOR, truncation and rounding…

Read article →
Databases & SQL

Recursive CTE in SQL: Hierarchies, Paths, Series and Cycles

Recursive CTE in SQL explained with tested queries: org charts with levels and paths, walking up a tree, team sizes,…

Read article →
Software Development

JavaScript Deep Copy: structuredClone vs JSON vs Spread, Tested

JavaScript deep copy compared: spread, Object.assign, the JSON trick, structuredClone and a custom copy, tested on Dates, Maps, Sets, BigInt…

Read article →
Artificial Intelligence

K Means Clustering Explained: How It Works, With Python Code

K means clustering explained: the algorithm, a from-scratch NumPy version, choosing k with the elbow and silhouette methods, k-means++, scaling…

Read article →
DevOps

Git Log Explained: 15 Useful Commands and Pretty Formats

Git log explained with 15 tested commands: oneline, graph, filters by author, date, message and code, file history, stats, pretty…

Read article →
Test Automation

Pytest conftest.py Explained: Shared Fixtures, Hooks and Overrides

Pytest conftest.py explained with a tested suite: shared fixtures, scope and teardown, folder overrides, autouse, custom options, markers and useful…

Read article →
Software Testing

Usability Testing: Methods, Metrics, SUS Score and Checklist

Usability testing explained: methods, planning, writing tasks, running sessions, metrics, SUS scoring, how many users you need and a practical…

Read article →
Databases & SQL

SQL UPDATE Statement: Safe Updates, UPDATE With JOIN and RETURNING

The SQL UPDATE statement explained with tested examples: WHERE guards, CASE updates, UPDATE with JOIN, the subquery NULL trap, RETURNING…

Read article →
Databases & SQL

SQL COUNT: COUNT(*) vs COUNT(column) vs COUNT(DISTINCT) Explained

SQL COUNT explained: COUNT(*) vs COUNT(column) vs COUNT(DISTINCT), NULLs and empty strings, conditional counts, HAVING, the LEFT JOIN trap and…

Read article →
Artificial Intelligence

K Nearest Neighbors (KNN) Explained: How It Works, With Python Code

K nearest neighbors explained: the KNN algorithm, a from-scratch NumPy version, choosing k, feature scaling, distance metrics, regression and vector…

Read article →
DevOps

Git Rebase Interactive: Squash, Fixup, Reword and Autosquash

Git rebase interactive explained step by step: pick, reword, squash, fixup, edit, drop, autosquash, conflicts and undoing a rebase with…

Read article →
Software Testing

Alpha vs Beta Testing: Key Differences, Exit Criteria and Checklist

Alpha vs beta testing compared: who tests, what each phase finds, entry and exit criteria, how to run a beta,…

Read article →
Test Automation

Pytest Monkeypatch: 10 Tested Examples for Env Vars, Time and APIs

Pytest monkeypatch explained with 10 passing tests: environment variables, functions, config, time, sleeps, paths, blocking the network and the wrong-target…

Read article →
Artificial Intelligence

Softmax Function Explained: Formula, Python Code and Stable Version

The softmax function explained: formula, worked example, NumPy code, the stable version that avoids NaN, temperature, cross-entropy and softmax vs…

Read article →
DevOps

Git Diff Explained: Staged Changes, Branches and Commits

Git diff explained: read the output, compare unstaged and staged changes, commits and branches, two dots vs three dots, and…

Read article →
Test Automation

Pytest Xdist: Run Tests in Parallel and Cut Test Time

Run pytest tests in parallel with pytest-xdist: install, the -n option, distribution modes, real timings and how to fix shared-state…

Read article →
Software Testing

Verification vs Validation in Software Testing: Example and Table

Verification vs validation in software testing explained with a comparison table and a tested coupon example where every spec test…

Read article →
Artificial Intelligence

Levenshtein Distance: Formula, Worked Table and Python Code

Levenshtein distance explained: the edit operations, the dynamic programming table for kitten and sitting, Python code with two-row memory, normalised…

Read article →
DevOps

Gitignore: Patterns, Negation and Fixing Tracked Files

A tested gitignore guide: pattern rules, leading and trailing slashes, negation with !, the ignored parent folder trap, git check-ignore…

Read article →
Software Testing

Acceptance Criteria: Given When Then Examples and Checklist

How to write acceptance criteria testers can run: rule-based and Given When Then formats, a worked discount code example turned…

Read article →
Test Automation

Python Unittest: Assert Methods, setUp and Mocks With Examples

A practical Python unittest tutorial: TestCase, assert methods, setUp and tearDown, subTest, skips, expected failures and mock, with a test…

Read article →