Skip to main content

Claude/ChatGPT Prompt to Bisect a Git Regression in Minutes

Find the exact commit that introduced a bug with git bisect, an automated test script, and a clean revert-or-fix decision.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
You are a senior engineer debugging a production regression. Return runnable commands and a real bisect test script, not pseudocode.

Context:
- Bug: checkout totals are off by $0.01 since Tuesday
- Known-good reference: v2.3.0
- Known-bad reference: HEAD
- Repo language/test runner: PHP + PHPUnit

Deliverables:
1. The exact git bisect start sequence using my good and bad references.
2. A self-contained test script for git bisect run that exits 0 when the bug is absent and non-zero when present, with a skip code for builds that fail to compile.
3. How to handle merge commits and flaky tests so bisect does not point at the wrong commit.
4. Commands to confirm the culprit (git show, git log) once bisect lands on it.
5. A revert-vs-fix-forward decision rule, with the safe revert command and how to reset bisect state.

Output: numbered commands and the test script in fenced blocks, copy-ready for my terminal.

What this prompt does

This prompt frames the model as a senior engineer debugging a production regression and asks for runnable commands and a real git bisect test script, not pseudocode. Four placeholders make it specific: [bug_description] (the regression you are hunting), [good_ref] (a known-good commit or tag), [bad_ref] (a known-bad reference), and [stack] (the language and test runner the script targets).

The structure works because bisect is only as good as its test script. By demanding the exact git bisect start sequence from your refs, a self-contained script that exits 0 when the bug is absent and non-zero when present with a skip code for un-buildable commits, handling for merge commits and flaky tests, commands to confirm the culprit, and a revert-vs-fix-forward rule, the prompt automates the search instead of leaving you guessing. The skip code (exit 125) keeps bisect from marking un-buildable commits as bad. Tailoring the script to [stack] matters because the build and test invocation differs by language and runner, and a script that does not actually exercise the regression will send bisect to a confidently wrong answer.

When to use it

  • Something broke "sometime this week" and you need to find the exact offending commit fast.
  • You want a scripted git bisect run rather than manually testing each step.
  • You have a clear [good_ref] and [bad_ref] to bound the search.
  • You need a test script for [stack] that exits correctly per bug presence.
  • Your history has merge commits or flaky tests that could misdirect a naive bisect.
  • You want a clear revert-vs-fix-forward decision rule once the culprit is found.

Example output

Expect numbered commands and a fenced test script. It starts with the git bisect start sequence using [good_ref] and [bad_ref], then a self-contained script for git bisect run written for [stack] that exits 0 when [bug_description] is absent, non-zero when present, and 125 to skip builds that fail to compile. It adds guidance on merge commits and flaky tests, commands to confirm the culprit with git show/git log, and a revert-vs-fix-forward decision rule with the safe revert command and how to reset bisect state.

Pro tips

  • Make the script exit 125 on un-buildable commits so bisect skips them instead of wrongly marking them bad.
  • Describe [bug_description] as something the script can detect deterministically; a vague symptom makes the automated run unreliable.
  • Pick a [good_ref] you are genuinely sure about — if the bug already exists there, bisect points at the wrong commit.
  • Address flaky tests up front (retry or pin) so flake does not send bisect down the wrong path.
  • Once it lands, confirm with git show before reverting, then reset bisect state so your working tree is clean.
  • Verify the script manually against [good_ref] and [bad_ref] first — it should pass on one and fail on the other before you trust an automated run.
  • For an intermittent [bug_description], run the check several times inside the script so a single lucky pass does not mark a bad commit as good.

Frequently Asked Questions

What does the test script need to return?
It must exit 0 when the bug is absent and non-zero when present, plus exit 125 to skip commits that fail to build. That skip code is what stops bisect from marking un-buildable commits as bad and pointing at the wrong culprit.
Will flaky tests mess up the bisect?
They can, which is why deliverable three covers handling merge commits and flaky tests. A flaky test can mark a good commit as bad, so the prompt addresses pinning or retrying to keep the search pointing at the real regression.
Do I need to know exactly where the bug started?
No, you only need bounds: a `[good_ref]` you are confident is clean and a `[bad_ref]` that has the bug. Bisect narrows the range between them automatically, which is the whole point of the technique.
What does it suggest once the commit is found?
Deliverable five gives a revert-vs-fix-forward decision rule, the safe revert command, and how to reset bisect state. It helps you choose based on risk rather than reflexively reverting or patching.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Git & GitHub Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support