Binary search through commit history to find the commit that introduced a bug. This is incredibly efficient - even with 1000 commits, you’ll find the culprit in about 10 steps.
# 1. Start bisect sessionwit bisect start# 2. Mark current commit as bad (has the bug)wit bisect bad# 3. Mark a known good commit (before the bug existed)wit bisect good v1.0.0# 4. wit checks out a commit in the middle - test it# ... test the code ...# 5. Mark as good or bad based on your testwit bisect good # Bug not present# orwit bisect bad # Bug is present# 6. Repeat step 4-5 until wit finds the culprit# ✓ Found the first bad commit!# abc1234 is the first bad commit# John Doe: Add new feature# 7. End the sessionwit bisect reset
wit bisect start # Start bisect sessionwit bisect good [<rev>] # Mark commit as good (no bug)wit bisect bad [<rev>] # Mark commit as bad (has bug)wit bisect skip # Skip current commit (can't test)wit bisect reset # End session, return to original statewit bisect log # Show bisect historywit bisect status # Show current bisect state
# Start bisectwit bisect start# ✓ Bisect session started# Now mark commits as good or bad# We know HEAD is brokenwit bisect bad# ✗ Marked as bad# We know v1.0.0 workedwit bisect good v1.0.0# ✓ Marked as good# Bisecting: 15 commits left to test# (roughly 4 steps remaining)# Testing: abc1234# Jane Doe: Refactor API# Test the code at this commitnpm test# It passes, so this commit is goodwit bisect good# ✓ Marked as good# Bisecting: 7 commits left to test# (roughly 3 steps remaining)# Testing: def5678# Keep going until...# ✓ Found the first bad commit!# ghi9012 is the first bad commit# Bob Smith: Update dependencieswit bisect reset# ✓ Bisect session ended# Restored to branch: main
# Show the last commitwit show# Show specific commitwit show abc1234# Show with stats onlywit show --stat abc1234# Show file names onlywit show --name-only abc1234
# Show file contents at a specific commitwit show abc1234:src/config.ts# Show file at HEADwit show HEAD:package.json# Show file from 3 commits agowit show HEAD~3:README.md
wit show v1.0.0# tag v1.0.0# Tagger: Jane Doe <jane@example.com># Date: Fri Mar 15 14:30:00 2024## Release version 1.0.0## commit abc1234...# Author: Jane Doe <jane@example.com># ...
# See what changed in a commit (summary)wit show --stat HEAD# src/auth.ts | 50 +++++++++++++++# src/routes.ts | 12 ++--# 2 files changed, 55 insertions(+), 5 deletions(-)# List files changed in a commitwit show --name-only abc1234# src/auth.ts# src/routes.ts# See file statuswit show --name-status abc1234# A src/auth.ts# M src/routes.ts
Clean requires explicit flags to prevent accidental data loss:
Copy
# Preview what would be deleted (always do this first!)wit clean -n# Actually delete fileswit clean -f# Delete files and directorieswit clean -fd# Also delete ignored files (like node_modules, build/)wit clean -fx
# Clean up after a failed buildwit clean -fd# Start completely fresh (like a new clone)wit clean -fdxnpm install# Clean up temp files but keep build artifactswit clean -f -e "build/*" -e "dist/*"
# 1. Clean up the workspacewit clean -n # Previewwit clean -f # Clean# 2. Find when bug was introducedwit bisect startwit bisect bad HEADwit bisect good v1.0.0# ... test and mark commits ...wit bisect reset# 3. Examine the bad commitwit show <bad-commit>wit show <bad-commit>:path/to/file.ts# 4. Check what the file looked like beforewit show <bad-commit>~1:path/to/file.ts