git log Power Tricks
Bas sahi flags seekho — aur git log tumhara daily driver ban jayega.
git log by default shows ALL commits in reverse chronological order — overwhelming and useless when your project has hundreds or thousands of commits.
But git log has incredibly powerful FILTERING options that most developers never learn. These filters turn git log from a simple history viewer into a search engine for your codebase.
The five key filters:
- Filter by AUTHOR:
git log --author="Alice"— show only Alice's commits. - Filter by DATE:
git log --since="2 weeks ago",--until="yesterday",--after="2024-01-01". - Filter by MESSAGE:
git log --grep="bug"— search commit messages for "bug". - Filter by FILE:
git log -- app.js— show only commits that changed app.js. - Filter by CONTENT:
git log -S "functionName"— find commits that added/removed text (pickaxe — next chapter).
The real power is COMBINING filters. Each one narrows the results further, like a search engine refining results.
# Basic log — overwhelming
git log
# Shows EVERY commit. Not useful.
# Filter by author
git log --author="Alice" --oneline
# Filter by date
git log --since="2 weeks ago" --oneline
git log --after="2024-01-01" --before="2024-02-01" --oneline
# Filter by commit message
git log --grep="JIRA-123" --oneline
git log --grep="fix" -i --oneline # -i = case insensitive
# Filter by file/path
git log -- app.js --oneline
git log -- src/components/ --oneline
# The ULTIMATE combo
git log --author="Alice" --since="last month" --grep="feat" --oneline -- src/
# "Show Alice's feature commits from last month that touched src/"
--oneline shows one line per commit: short hash + message. Good for a quick overview of many commits.
--stat shows which files changed and how many insertions/deletions per commit. Great for understanding impact.
--graph draws a visual branch graph with ASCII art. Shows branching and merging history at a glance.
--pretty=format:"..." gives you completely custom output. The most useful format placeholders:
%h= short hash,%H= full hash%an= author name,%ae= author email%s= subject (commit message first line)%ar= relative date ("2 weeks ago")%d= ref names (branches, tags)
The GOD command: git log --oneline --graph --all — visual graph of ALL branches. This single command shows your entire repository structure.
-5 or -n 5 limits output to the last 5 commits. git log -p shows the full diff of each commit — detailed but long.
# Custom format — your daily driver
git log --pretty=format:"%h | %an | %ar | %s" -10
# a1b2c3d | Alice | 2 days ago | feat: add login
# e5f6g7h | Bob | 1 week ago | fix: null check
# The GOD command — visualize all branches
git log --oneline --graph --all
# * a1b2c3d (HEAD -> main) feat: add login
# * e5f6g7h fix: null check
# | * i9j0k1l (feature) add dashboard
# |/
# * m3n4o5p initial commit
# Show what changed in each commit
git log --stat -5
# a1b2c3d feat: add login
# app.js | 15 +++++++
# auth.js | 42 +++++++++++++++++
# 2 files changed, 57 insertions(+)
# Show full diff of last commit
git log -p -1
# Create an alias for your favorite format
git config --global alias.lg "log --pretty=format:'%h %an %ar %s' --graph"
git lg # shortcut!
git log --oneline --graph --all is the single most useful git log command. It shows every branch, every merge, and the full topology of your repository. Memorize it. Better yet, create an alias: git config --global alias.lg "log --oneline --graph --all" and just type git lg.Date formats in git log are flexible and human-friendly:
--since="2024-01-15"— specific date--since="2 weeks ago"— relative date--since="yesterday",--since="3 hours ago"— natural language
--until or --before excludes commits after the given date. Combine with --since for a date range.
Commit ranges are incredibly powerful for comparing branches:
git log HEAD~5..HEAD— show only the last 5 commits.git log main..feature— commits on feature that are NOT on main. Perfect for PR review.git log feature...main— commits on EITHER branch but not both (symmetric difference).git log --merge— show only commits that conflict during merge. Useful during conflict resolution.
# Date range — what happened in January 2024?
git log --since="2024-01-01" --until="2024-02-01" --oneline
# Relative dates — last 2 weeks
git log --since="2 weeks ago" --oneline
# Yesterday's commits
git log --since="yesterday" --oneline
# Range: last 5 commits only
git log HEAD~5..HEAD --oneline
# What will be in my PR?
git log main..feature --oneline
# Shows only commits on feature that are NOT on main
# What changed since branches diverged?
git log main...feature --oneline
# Shows commits on EITHER branch since the split
# During merge conflicts
git log --merge --oneline
# Shows only the conflicting commits
main..feature is one of the most useful git log tricks. It shows ONLY the commits that are on feature but not on main — exactly what will be in a pull request. Before creating a PR, run git log main..your-branch --oneline to see what you're about to merge.git log -- path/ shows commits that changed anything under that path. This is how you answer "who changed the auth module?"
git log -- file1.js file2.js shows commits that changed either file. Multiple paths are OR-ed together.
The -- separator is CRITICAL: it tells Git "everything after this is a file path, not a branch name." Without --, Git might interpret main as a branch instead of a file named "main".
git log --follow -- file.js follows the file across renames. See history even after the file was renamed — without this, commits before the rename are invisible.
git log -S "text" -- file.js searches for text changes within a specific file. Combines content search with file filtering.
git log -L :functionName:file.js shows the history of a specific function (line log). Only shows commits that changed that function — incredibly precise.
# Commits that changed a specific file
git log --oneline -- app.js
# Commits that changed files in a directory
git log --oneline -- src/auth/
# CRITICAL: always use -- before file paths
# Without --: Git thinks "main" is a branch
git log main # branch name
git log -- main # file/directory named "main"
# Follow renames — see history before file was renamed
git log --follow --oneline -- app.js
# Shows commits from when the file was called application.js too
# History of a specific function (line log)
git log -L :login:auth.js
# Shows only commits that changed the login() function
# Find who deleted a function in a specific file
git log -S "validateUser" --oneline -- auth.js
# Shows commits that added/removed "validateUser" in auth.js
git log main shows the branch, not the file. git log -- main shows the file. Always use -- before paths. And always use --follow when checking file history — without it, you miss the commits before any rename.Real questions you face every day — and the git log commands that answer them:
- "What did I do last week?"
git log --author="me" --since="1 week ago" --oneline - "What changed in the auth module this month?"
git log --since="1 month" --oneline -- src/auth/ - "What bug fixes went into v2.0?"
git log v1.0..v2.0 --grep="fix" --oneline - "What will be in my PR?"
git log main..my-branch --oneline - "Who has been working on the API?"
git log --oneline -- src/api/ | awk '{print $2}' | sort | uniq -c | sort -rn - "What changed between yesterday and today?"
git log --since="yesterday" --oneline - "Show me a summary for standup"
git log --since="1 day ago" --pretty=format:"- %s" --author="me"
# Daily standup report
git log --since="1 day ago" --pretty=format:"- %s" --author="$(git config user.name)"
# - feat: added login page
# - fix: null check on logout
# - chore: updated dependencies
# What bug fixes are in the release?
git log v1.0..v2.0 --grep="fix" -i --oneline
# Who changed this file most?
git log --format="%an" -- auth.js | sort | uniq -c | sort -rn
# 12 Alice
# 8 Bob
# 3 Charlie
# What is in my PR? (most useful command ever)
git log main..HEAD --oneline
# Code review: what did my teammate change?
git log --author="Bob" --since="yesterday" --stat
git log and git log --oneline. Learning the filtering options makes you 10x more effective at answering questions about your code's history.Lo kar liya — Key Points:
- ✅ git log has powerful filtering: --author, --since/until, --grep, -- path, -S for content search
- ✅ Use --oneline for quick overview, --stat for file changes, -p for full diffs
- ✅ --pretty=format lets you create custom output: %h hash, %an author, %s subject, %ar relative date
- ✅ The range syntax main..feature shows commits on feature that are NOT on main — perfect for PR review
- ✅ Always use -- before file paths to separate them from branch names
- ✅ --follow tracks file history across renames — see changes before the file was renamed
- ✅ Combine multiple filters for surgical precision: git log --author=Alice --since="1 month" --grep=feat -- src/
Want to track your progress?
Log in to save your place and pick up where you left off.
Progress track karna chahte ho?
Login karo apni progress save karne ke liye aur jahan chhoda tha wahan se shuru karo.
Login