Skip to content

Latest commit

 

History

History
76 lines (57 loc) · 2.18 KB

archaeology.md

File metadata and controls

76 lines (57 loc) · 2.18 KB

Git Archaeology

When you are tracking down a bug or trying to understand why a specific change was made, Git offers powerful archaeology tools like grep and bisect.

Search for a pattern in tracked files

git grep is incredibly fast because it only searches through files tracked by Git, ignoring .git/ directories and built binaries entirely.

git grep $opts -e "$pattern"

Bisect: 1. Start bisect

git bisect uses binary search to find the exact commit that introduced a bug. You first start the bisect and then mark a known bad commit and a known good commit.

git bisect start

Bisect: 2. Mark bad commit

Mark the commit where the bug is currently happening. Usually this is your current HEAD.

git bisect bad $commit

Bisect: 3. Mark good commit

Mark a commit from the past where you know for a fact the bug did not exist. Git will then checkout a commit halfway between the good and bad commits.

git bisect good $commit

Bisect: 4. Test and mark current commit

Test the codebase at the newly checked out commit. If the bug is present, mark it bad. If it works, mark it good. Git will continue narrowing down the commits until it finds the exact culprit.

git bisect $status

Bisect: 5. Reset after finding bug

Once Git prints out the exact commit that caused the bug, use this command to end the bisect session and return your repository to where you started.

git bisect reset