Basic git log
git log is your window into a project's history. Every commit ever made on the current branch is stored in Git's database, and git log is how you read that history. Whether you are investigating a bug, reviewing what changed last week, or figuring out who wrote a particular piece of code, this is the command you reach for.
Running git log with no arguments shows the full commit history on the current branch, starting from the most recent commit:
Each commit entry shows four pieces of information:
- Commit hash — the full 40-character SHA-1 identifier that uniquely identifies this commit across the entire repository
- Author — the name and email of the person who created the commit
- Date — when the commit was created
- Message — the commit message explaining what changed and why
The default output is verbose. For a project with thousands of commits, scrolling through this format is impractical. That is where flags come in.
Useful flags
--oneline
The most popular flag by far. It compresses each commit to a single line showing only the abbreviated hash and the first line of the commit message:
Hover over each part to see what it does
This gives you a high-level overview of the project history at a glance. The abbreviated hash (7 characters by default) is almost always enough to uniquely identify a commit.
--graph
Add --graph to draw an ASCII art graph showing the branch and merge structure. This is most useful when combined with --oneline and --all to see every branch:
The lines and slashes show where branches diverge and merge. The --all flag includes all branches, not just the current one. Without it, you only see commits reachable from HEAD.
--author
Filter commits by author name or email. The match is a substring search, so you do not need the full name:
--since and --until
Limit the log to a date range. Git accepts many natural language formats:
You can use specific dates too: --since="2026-02-01" or combine both ends: --since="2026-02-01" --until="2026-02-15".
-n (limit count)
Show only the most recent N commits. Useful when you just need to see what happened recently:
These flags combine freely. A common combination is:
git log --oneline --graph --all --author="Alice" -n 20Filtering by file
One of the most practical uses of git log is viewing the history of a single file. Add a -- separator followed by the file path:
This shows only the commits that modified Header.tsx. It is invaluable when debugging — you can quickly see every change made to a file, by whom, and when.
Tracking renames with --follow
By default, git log -- path stops tracking a file if it was renamed. The --follow flag tells Git to follow the file across renames:
This is especially useful in projects where files get reorganized into new directory structures. Without --follow, the history would appear to start at the commit where the file was moved to its current location.
You can also filter by directory to see all changes within a folder:
git log --oneline -- src/components/Searching commits
Git offers two powerful ways to search through commit history: searching commit messages and searching the actual code changes.
Searching commit messages with --grep
The --grep flag filters commits whose message contains the given string. The search is case-sensitive by default:
Add -i for case-insensitive search: git log --grep="fix" -i. You can also pass multiple --grep flags to match any of them, or add --all-match to require all patterns.
Searching code changes with -S (pickaxe)
The -S flag, known as the "pickaxe", finds commits that changed the number of occurrences of a string. In practice, this means it finds commits where a function, variable, or any string was added or removed:
Hover over each part to see what it does
This is incredibly useful for answering questions like "When was this function introduced?" or "Which commit removed this configuration variable?"
Regex search with -G
While -S looks for changes in the count of a string, -G searches the actual diff content using a regular expression:
Use -G when you need pattern matching. For example, finding all commits that added an async function related to fetching, regardless of the exact function name.
Visual log in Komitly
The ASCII graph from git log --graph works, but it becomes hard to read with more than a few branches. Komitly replaces the text-based output with an interactive visual commit graph that renders branch lanes in color, making it immediately clear where branches diverge and merge.
The graph above shows the same history as the terminal output, but with color-coded lanes for each branch. You can see at a glance that feature/auth and feature/ui both branched off from main at the same commit. Click any commit to see its full details, diff, and changed files.
Komitly adds several features that make navigating history faster than the command line:
- Search by message, author, or hash — type in the search bar and the graph filters in real time. No need to remember flag syntax.
- Click to view diff — select any commit to see exactly which files changed, with a full side-by-side or unified diff view including syntax highlighting.
- File tree at any commit — right-click a commit and browse the complete file tree as it existed at that point in time.
- Branch filtering — hide branches from the graph to reduce visual noise when the repository has many active branches.
- Reflog view — switch to the reflog panel to see all HEAD movements, including operations that
git logdoes not show, like resets, rebases, and stash operations.
The visual approach is especially valuable during code review and debugging. Instead of piecing together a mental model from text output, you see the branch structure directly and can click through commits to find the one that introduced a change.
Tips and tricks
Here are some techniques that experienced Git users rely on daily.
Create aliases for common log formats
Typing long flag combinations repeatedly gets tedious. Set up Git aliases to create shortcuts:
git config --global alias.lg "log --oneline --graph --all --decorate"
git config --global alias.recent "log --oneline -n 10"
git config --global alias.who "shortlog -s -n --all"Now git lg gives you the full graph view, git recent shows the last 10 commits, and git who shows a leaderboard of commit counts by author.
Custom format with --pretty
The --pretty=format: option lets you define exactly what information to show. Here are some useful placeholders:
%h— abbreviated commit hash%an— author name%ar— relative date (e.g. "2 days ago")%s— commit subject (first line of message)%d— ref names (branch, tag)
A popular custom format that packs a lot of information into one line:
git log --pretty=format:"%h %C(yellow)%ar%C(reset) %C(blue)%an%C(reset) %s%C(green)%d%C(reset)"
# Output:
# 3a1b2c3 2 days ago Alice Chen Add user authentication flow (feature/auth)
# 7f2e4a1 3 days ago Bob Martinez Fix null pointer in settings page (main)
# c8d9e0f 4 days ago Alice Chen Refactor database connection poolingThe %C(color) placeholders add terminal colors. Save this as a Git alias and you have a compact, colorful log that rivals any GUI.
View what changed with -p and --stat
Add -p (or --patch) to see the actual diff for each commit. This is how you find out not just that a file changed, but exactly what lines were added or removed:
git log -p -n 1 # show the diff for the last commit
git log --stat -n 5 # show file change summary for last 5 commitsThe --stat flag shows a summary with file names and a bar chart of insertions and deletions — a nice middle ground between the default output and the full patch.
Compare branches with log
The double-dot and triple-dot syntax lets you compare branches:
# Commits in feature/auth that are not in main
git log main..feature/auth --oneline
# Commits in either branch but not in both
git log main...feature/auth --onelineThis is extremely useful before merging. You can see exactly which commits will be introduced to main when the feature branch is merged.
git logis one of the most versatile commands in Git. You do not need to memorize every flag — just learn--oneline,--graph, and-S, and you will be ahead of most developers. Or use a visual tool like Komitly and skip the flags entirely.