Lesson Completion
Back to course

History Search Cheat Sheet

Beginner
5 minutes4.8Git

The Hook (The "Byte-Sized" Intro)

When history gets noisy, a cheat sheet keeps you fast. Here's every Git history command you need — organized by the question you're trying to answer. Print it. Pin it. Never google "how to find who changed this line" again.

📖 History Search Quick Reference

🔍 "What happened?"

QuestionCommand
Recent commitsgit log --oneline -10
Graph viewgit log --oneline --graph --all
Changes in a filegit log --oneline -- file.js
Changes between releasesgit log v1.0..v2.0 --oneline
Skip merge commitsgit log --no-merges --oneline

👤 "Who did this?"

QuestionCommand
Who wrote this line?git blame file.js
Blame specific linesgit blame -L 10,20 file.js
Ignore whitespacegit blame -w file.js
Track moved codegit blame -C file.js
Filter by authorgit log --author="name"

📅 "When did this happen?"

QuestionCommand
Since a dategit log --since="2026-01-01"
Last 2 weeksgit log --since="2 weeks ago"
Between datesgit log --since="Jan 1" --until="Feb 1"
When code was addedgit log -S "code" --oneline

🐛 "What introduced this bug?"

QuestionCommand
Binary searchgit bisect start HEAD v1.0
Mark goodgit bisect good
Mark badgit bisect bad
Automategit bisect run npm test
End bisectgit bisect reset

🔎 "Where is this code?"

QuestionCommand
Search tracked filesgit grep "term"
With line numbersgit grep -n "term"
Files onlygit grep -l "term"
Count per filegit grep -c "term"
At a specific versiongit grep "term" v1.0
In specific file typesgit grep "term" -- "*.js"

📊 "What changed between X and Y?"

QuestionCommand
Diff two commitsgit diff A..B
File summarygit diff A..B --stat
Changed filenamesgit diff --name-only A..B
From fork pointgit diff A...B
Commits in B not Agit log A..B --oneline

🔧 "Low-level inspection"

QuestionCommand
Object typegit cat-file -t SHA
Object contentgit cat-file -p SHA
Full SHA from shortgit rev-parse SHORT
Closest taggit describe
Dangling objectsgit fsck --unreachable

Key Takeaways

  • Organize your search by the question you're asking.
  • log for history, blame for attribution, bisect for bugs, grep for content.
  • Combine filters for precision: --author + --since + -- path.
  • Bookmark this cheat sheet for quick reference.

Interview Prep

  • Q: What are the main Git tools for searching history? A: git log (with filters) for commit history, git blame for line-by-line attribution, git log -S (pickaxe) for when code was added/removed, git bisect for finding bug-introducing commits, and git grep for searching current/historical file content.

  • Q: How do you combine multiple search criteria? A: Chain filters on git log: git log --author="name" --since="date" --grep="keyword" -- path/to/file. Filters are ANDed together for precise results.

  • Q: What is the fastest way to find a regression's root cause? A: git bisect run <test-script>. Provide a known-good and known-bad commit, and Git automatically binary-searches through the history, running your test at each midpoint. It finds the first bad commit in O(log n) steps.

Topics Covered

Git HistoryReference

Tags

#git#cheat-sheet#search#reference

Last Updated

2026-02-13