amaslenn.github.com

View My GitHub Profile

Git: worktree + bisect = ♥

Git worktree - create branch in separate folder
Git bisect - search for the first bad commit

Motivation

Bisecting may take a while and it makes repository “taken” so no work can be done in it until bisect finished.

Create new worktree

git worktree add -b branch-name <path>
cd <path>

Define “good” and “bad” revisions

git checkout <good-revision>
# run check to make sure it reports **PASS**
git checkout <bad-revision>
# run check to make sure it reports **FAIL**

Bisect

git bisect start
git bisect good <good-revision>
git bisect bad <bad-revision>
git bisect run <check script>
git bisect reset

Notes on bisect script

Verification script must return 0 for success, everything between 1 and 127 (inclusively) are treated as error. 125 has a special meaning, it skips commit. Everythig else breaks the bisect process.

Clean up worktree

rm -rf <path>
git worktree prune    # cleans up `.git/worktrees

Summary

Using bisect alone is the fastest way to find buggy commit. Adding worktree to this workflow helps with time saving: you can continue your work while bisect is looking for bugs for you. No more I should wait or N+ cloned repos.