Debugging_and_Optimizing_Git_History
Debugging and Optimizing Git History
Find bugs and clean up history.
π git bisect
Start Bisect
git bisect start
Begins binary search.
git bisect bad
Current commit is broken.
git bisect good v1.0.0
This version worked.
Test and Mark
git bisect good
This commit works.
git bisect bad
This commit is broken.
Finish
git bisect reset
Returns to original state.
Automate
git bisect run npm test
Automatically bisects using test command.
π€ git blame
Find Author of Lines
git blame filename.txt
Shows who wrote each line.
Specific Lines
git blame -L 10,20 filename.txt
Blame lines 10-20 only.
Ignore Whitespace
git blame -w filename.txt
Ignores formatting changes.
Show Email
git blame -e filename.txt
Shows email instead of name.
π Log Search
Find by Code
git log -S "functionName"
Finds commits adding/removing this code.
Find by Message
git log --grep="fix"
Finds commits with "fix" in message.
Find by File Change
git log -- path/to/file.txt
History of specific file.
π Interactive Rebase
Clean Last 5 Commits
git rebase -i HEAD~5
Opens editor to modify commits.
Options:
pick- keepreword- change messagesquash- combine with previousdrop- remove
Squash All Into One
git rebase -i --root
Rebases from first commit.
βοΈ Amend Commits
Fix Last Commit Message
git commit --amend -m "Corrected message"
Changes last commit message.
Add Files to Last Commit
git add forgotten-file.txt
Stage forgotten file.
git commit --amend --no-edit
Add to last commit.
π§Ή History Optimization
Garbage Collect
git gc
Cleans up and compresses.
Aggressive Cleanup
git gc --aggressive
Thorough optimization.
Prune Unreachable
git prune
Removes unreachable objects.
π‘ Tips
Find Deleted Code
git log -S "deleted_function" --all
Who Deleted a Line
git log -p -- filename | grep -B 5 "deleted text"
π Related
#git #debug #history #optimize