C.W.K.
Stream
Lesson 03 of 05 · published

bisect: 버그를 이분 탐색하기

~24 min · bisect, debugging

Level 0Untracked 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

bisect — history 통과 binary search

버그 있어. 버전 1.4 에서 작동하고 2.0 에서 망가져. 사이 200 commit 어딘가에 regression 살아. 수동 검색은 비참. git bisect 가 그 범위 자동 binary-search 의 이름 있는 레시피: Git 이 절반 commit checkout, 너가 good / bad 말함, Git 이 반으로 좁힘, 반복. log₂(200) 은 약 7 — test 7 번이면 정확한 범인 commit 찾음.

동작 단순. git bisect start, 망가진 commit (또는 지금 git bisect bad HEAD) 에 git bisect bad, 알려진-좋은 commit 에 git bisect good v1.4. Git 이 중간점 checkout. 빌드, 테스트, 결정, git bisect good 또는 git bisect bad. Git 이 다음 중간점 checkout. Git 이 첫 안 좋은 commit 발표할 때까지 반복. git bisect reset 으로 원래 branch 복귀.

자동화 업그레이드: git bisect run <script>. 'good' 에 exit 0, 'bad' 에 non-zero 인 스크립트 제공 — 보통 test 명령, 또는 grep -q "expected output" log.txt 같은 한 줄 체크. Git 이 각 중간점에 자동 실행, 사람 없이. v1.4 와 HEAD 사이 20 commit 은 초 단위. 느린 빌드의 수백 commit 은 시간 단위, 하지만 그 동안 너는 아무것도 안 해.

실전 세련화 둘. 흥미롭지 않은 commit 건너뛰기 — 특정 checkpoint 가 테스트 불가일 때 (broken build, missing dep 등) git bisect skip, Git 이 다른 후보 시도. Bisect 로그 저장git bisect log > my-bisect.log 후 나중에 git bisect replay my-bisect.log 로 replay (포기 후 재개 필요할 때). Bisect run 은 branch 와 간섭 안 하는 작은 side-state.

Code

수동 bisect — 전형적 세션·bash
# 검색 시작, Git 에 bad / good 끝 알리기:
git bisect start
git bisect bad HEAD
git bisect good v1.4.0

# Git 이 중간점 commit checkout. 테스트:
npm test
# 또는 실제 증상 체커 실행:
./scripts/check-bug.sh

# 결정 + Git 에 말함:
git bisect good       # 또는: git bisect bad

# Git 이 발표할 때까지 반복:
# 'abc1234 is the first bad commit'

# 시작점 복귀:
git bisect reset
자동화 bisect run·bash
# Exit-code 스크립트 제공. 예:
git bisect start HEAD v1.4.0
git bisect run npm test           # 매 단계 full test suite

# 또는 집중 체크:
git bisect run bash -c 'npm run build && grep -q OK dist/output.txt'

# 또는 단일 test 호출:
git bisect run npm test -- search-results.test.js

# 캡처 + replay:
git bisect log > bisect-2026-05-03.log
# ... 며칠 후 재방문:
git bisect replay bisect-2026-05-03.log

External links

Exercise

Scratch repo 에 가짜 regression 구성: 일부러 틀린 상수 도입하는 commit + 관련 없는 일 하는 commit 6 개 더. git bisect 수동 실행, 단계마다 good/bad 결정, Git 이 도입 commit 가리키는지 확인. 그 다음 안 좋은 상수 탐지하는 한 줄 스크립트 작성, 그것에 대해 git bisect run. 시간 + 노력 차이 적어.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.