هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
Step by step
- Know a good and a bad point — a tag, a commit, a date. A test that tells good from bad in a minute (a unit test, a
curl, a script). - Start and mark both ends (quick answer). Git checks out the middle commit:
git bisect good v1.4.0
Bisecting: 98 revisions left to test after this (roughly 7 steps)
[4f2e1d0…] Refactor session handling- Test and answer — build/run your test, then
git bisect goodorgit bisect bad. A commit you can not test (does not build):git bisect skip. - Automatic — a script that exits
0for good and1for bad; Git runs the whole search alone:
#!/usr/bin/env bash
set -euo pipefail
pip install -q -r requirements.txt
pytest -q tests/test_login.pychmod +x test-login.sh
git bisect start HEAD v1.4.0
git bisect run ./test-login.sh
3f9c2e1… is the first bad commitExit code 125 from the script means "skip this commit".
- Read the result:
Attach the log to the ticket.
- Finish — always go back to where you were:
git bisect resetCheck that it worked
git bisect names one commit; checking out the commit before it passes the test, and the named commit fails it — then you know exactly which change to fix or revert.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| The result looks wrong | One good/bad answer was a mistake (flaky test). | git bisect log, edit it, git bisect replay; use a stable test. |
| Many commits do not build | Broken intermediate commits. | git bisect skip (or exit 125 in the script). |
| You are left in "detached HEAD" | Bisect still running. | git bisect reset. |
| The test script needs files that old commits lack | The script lives in the repo. | Keep the script outside the repo (or in /tmp). |
| Merges make the result a merge commit | The bug came from the combination. | git bisect start --first-parent to stay on main's line, then inspect that merge. |
| Takes long to build each step | Heavy builds. | Faster test (one unit test), cache dependencies. |
Go further
- Command pages: git.
- Next how-tos: Undo the last Git commit, Make a release with a Git tag, Park unfinished work with git stash.
- Learn it: Git — bisect, Git — blame.
- Practise: Lab: find the bad commit with bisect, park work with stash, release with a tag.
1About how many steps does bisect need for 200 commits?
About 8 — it halves the range each time (log₂ 200).
2How do you make git bisect run the search alone?
git bisect run ./script.sh — exit 0 = good, 1 = bad, 125 = skip.