Nâng CaoGit iconGit

`git bisect` hoạt động như thế nào? Scenario thực tế dùng nó tìm commit gây regression?

git bisect dùng binary search để tìm commit đầu tiên gây ra bug — thay vì manual check từng commit.

Workflow:

bash
git bisect start
git bisect bad                    # current HEAD là bad
git bisect good v1.3.0            # version này còn good
# Git checkout commit ở giữa good và bad
# Test: chạy test hoặc reproduce bug thủ công
git bisect good                   # commit này không có bug
# Git checkout commit tiếp theo
git bisect bad                    # commit này có bug
# ... tiếp tục ~7-8 lần cho 100 commits
# Git output: "abc123 is the first bad commit"
git bisect reset                  # về HEAD ban đầu

Tự động hóa với script:

bash
git bisect start HEAD v1.3.0
git bisect run npm test -- --testNamePattern="payment calculation"
# Git tự chạy test và tự đánh good/bad

Ví dụ thực tế: release mới bị báo cáo "số tiền hiển thị sai". git log --oneline thấy 87 commits từ lần release cuối. Bisect tự động với test case → tìm ra commit trong 7 bước thay vì check 87 commits.

Lưu ý: script phải return exit code 0 (good) hoặc non-zero (bad). Dùng git bisect skip khi commit không thể test (build broken).

Xem toàn bộ Git cùng filter theo level & chủ đề con.

Mở danh sách Git