cuckcoding.pro
Menu

Cherry-pick one useful fix from an AI branch

You asked the agent to stop inventory dropping below zero. It returned a working fix and an executive rebrand nobody ordered. The changes landed in separate commits. You can lift the one you need, preserve the other branch for discussion and avoid reviewing the same banner for a third time.

Before you start
Git 2.28+, Node.js 22+ and a POSIX shell. Start in an empty parent directory and run the blocks from top to bottom in the same terminal.
What to verify
Move only the inventory fix to main. Keep its existing rules file, omit the banner and verify the results for zero, one and three available seats.

Set up the two branches

Create a function that sells one seat from the available count. As written, selling from zero produces negative inventory. Record that version before creating the experimental branch. Both branches now have the same starting commit to compare against.

Terminal
mkdir chair-lab
cd chair-lab
git init -b main
git config user.name "Lab Reviewer"
git config user.email "reviewer@example.invalid"
printf '%s\n' 'export const seatsLeft = n => n - 1;' > seats.mjs
git add seats.mjs
git commit -m "Add seat counter"
git switch -c agent/experiment

The intended behaviour is that zero remains zero, one becomes zero and three become two. Those examples will be useful after we move the fix.

Split the useful change from the sales pitch

Write the guard and commit it. Tag that commit before adding the banner in a second commit. In an existing repository you would inspect the log and copy the fix’s commit ID. The tag lets everyone following this workshop use the same commands.

Terminal
printf '%s\n' 'export const seatsLeft = n => Math.max(0, n - 1);' > seats.mjs
git commit -am "Clamp available seats at zero"
git tag seat-fix
printf '%s\n' 'THE EXECUTIVE EDITION' > banner.txt
git add banner.txt
git commit -m "Give the chair an executive banner"
git log --oneline main..HEAD

The branch log should list the banner and the clamp as two different entries. A branch name alone would point at its latest commit, which happens to be the one you do not want.

Inspect both the patch and its surroundings

Switch to main and give it a small independent documentation change. Inspect exactly what the tagged commit did to seats.mjs. Then compare the original fork point with the experiment branch to see the full proposal you would have accepted by merging it.

Terminal
git switch main
printf '%s\n' 'Seats are whole numbers.' > rules.txt
git add rules.txt
git commit -m "Record the integer constraint"
git show seat-fix -- seats.mjs
git diff --stat main...agent/experiment

The single commit changes one arithmetic expression. The complete proposal touches two files. The independently committed rules.txt belongs to main and should survive the transfer.

Apply one commit and test the result

Cherry-pick the tag on main. The -x option records the source commit ID in the message on this clean application. Check the resulting commit and then exercise the function at the boundary and on a normal sale.

Terminal
git cherry-pick -x seat-fix
git show --format=full --stat HEAD
node --input-type=module -e "
  import assert from 'node:assert/strict';
  import { seatsLeft } from './seats.mjs';
  assert.deepEqual([0, 1, 3].map(seatsLeft), [0, 0, 2]);
"
git ls-files

Successful assertions produce no output. The final file list contains rules.txt and seats.mjs. The original branch still holds its banner, so the marketing department may continue its important work elsewhere.

Try this prompt with your agent

Prompt
Inspect the commits on agent/experiment and identify the one that fixes negative inventory. Explain whether it depends on any earlier commit that main lacks. Show one command to apply just that fix and a check for zero, one and three seats.

A trap worth catching

A clean application means Git could apply the patch text. A borrowed fix can still depend on another change. Run the target branch’s tests. If a conflict appears, inspect git status and either resolve and continue, or run git cherry-pick --abort to return to the pre-pick state.

Official documentation