Vasu Patel logoVasu Patel
← Git Mastery
All chapters in this track
  1. 011. The Mental Model
  2. 022. Essential Setup
  3. 033. Core Daily Workflow
  4. 044. Branching
  5. 055. Merging & Conflict Resolution
  6. 066. Rebasing
  7. 077. Remote Repositories
  8. 088. Stashing
  9. 099. Undoing Things
  10. 1010. Tagging & Versioning
  11. 1111. Cherry-Pick
  12. 1212. Git Bisect & Blame
  13. 1313. Git Hooks
  14. 1414. Submodules
  15. 1515. Team Workflows
  16. 1616. Power Commands & Aliases
  17. 1717. Reflog: The Safety Net
  18. 1818. Practice Tasks
  19. 19Quick Reference Cheatsheet

Chapter 12 of 19

12. Git Bisect & Blame

Bisect — find which commit introduced a bug

Binary search through history. Cuts O(n) searches to O(log n).

git bisect start
git bisect bad                   # current commit is broken
git bisect good v1.2.0           # this tag was working

# Git checks out the midpoint commit
# Test your code, then:
git bisect good                  # if this commit works
git bisect bad                   # if this commit is broken

# Git narrows down until it prints:
# a1b2c3 is the first bad commit

git bisect reset                 # return to HEAD when done

# Automate with a test script
git bisect run python test.py    # 0 = good, non-zero = bad

Blame — see who last changed each line

git blame file.py                   # every line: commit + author + date
git blame -L 20,40 file.py          # limit to lines 20–40
git blame -w file.py                # ignore whitespace changes
git log -S "function_name" -- file  # find commit that added/removed a string
git log -G "regex"                  # search with regex

Tip: git blame is not about guilt — it's about understanding why code was written. Use git show <commit> after blame to read the full context.