GIT · Investigation · 10 min

Find the first broken revision

Let a repeatable test locate a regression in twelve changes.

Not completed

Your task

Use git bisect to find the first revision where status.txt stops containing ready. Save its hash in answer.txt, then exit bisect back to main.

What you’re aiming for

  • answer.txt contains the first failing commit hash.
  • main is checked out again and the bisect session is finished.

1. Prepare your practice folder

Use Git 2.28 or newer. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-git-bisect-first-failure && cd opsrung-git-bisect-first-failure

Run these setup commands in that folder:

SETUP — RUN ONCE
git init --initial-branch=main
git config --local user.name 'Practice Learner'
git config --local user.email 'practice@example.invalid'
printf '%s\n' 'A disposable OpsRung practice repository.' > README.txt
git add -- README.txt
git commit --allow-empty -m 'Start practice'
printf '%s\n' 'ready' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Working starting point'
git tag stable-release
printf '%s\n' 'ready' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 1'
printf '%s\n' 'ready' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 2'
printf '%s\n' 'ready' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 3'
printf '%s\n' 'ready' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 4'
printf '%s\n' 'ready' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 5'
printf '%s\n' 'ready' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 6'
printf '%s\n' 'blocked' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 7'
git rev-parse HEAD > .git/expected-bug
printf '%s\n' 'blocked' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 8'
printf '%s\n' 'blocked' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 9'
printf '%s\n' 'blocked' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 10'
printf '%s\n' 'blocked' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 11'
printf '%s\n' 'blocked' > status.txt
git add -- status.txt
git commit --allow-empty -m 'Revision 12'
Only if your personal Git settings interfere

You can normally skip this. If a commit asks for a signing key, runs a custom hook, or changes line endings unexpectedly, these repository-local overrides keep this disposable exercise independent of those settings.

OPTIONAL REPOSITORY OVERRIDES
git config --local commit.gpgsign false
git config --local core.autocrlf false
git config --local core.hooksPath .git/practice-no-hooks

Retry the failed command afterward. These settings apply only inside this practice repository.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

stable-release is a known good tag; the current tip is bad.

Hint 2

A test command must return 0 for good and nonzero for bad.

Hint 3

git bisect run can repeatedly execute grep -qx ready status.txt.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
cat answer.txt
git show --stat $(cat answer.txt)
git status

What you should see

  • answer.txt contains the first failing commit hash.
  • main is checked out again and the bisect session is finished.

If your result differs: Work only in this exercise’s repository. Compare the branch, files, and history with every goal before marking complete.

Compare with one possible solution
ONE POSSIBLE SOLUTION — BASH
git bisect start HEAD stable-release
git bisect run sh -c 'grep -qx ready status.txt'
git rev-parse HEAD > answer.txt
git bisect reset

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.