Skip to content

Commit 52bb943

Browse files
dschoGit for Windows Build Agent
authored andcommitted
fixup! Add an AGENTS.md file to help with AI-assisted debugging/development
AGENTS.md: document rebase, staging, and log -L tricks for AI agents Add practical recipes for three workflows that are particularly useful when AI agents work with Git: Non-interactive "interactive" rebases using `sed -i 1ib` as a sequence editor to insert a `break` command, then editing the todo file directly via the path from `git rev-parse --git-path rebase-merge/git-rebase-todo`. This avoids the impossible task of driving an interactive editor from an AI agent. Scripted hunk staging via `printf '%s\n' s y q | git add -p`, which feeds predictable keystrokes to the add-patch protocol to stage individual hunks without human interaction. The `git log -L <start>,+<count>:<file>` trick for finding which commit last touched specific lines, enabling an `hg absorb`-like workflow where the agent can identify the right fixup! target surgically rather than grepping through full diffs. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Assisted-by: Claude Opus 4.6
1 parent ea7f8ab commit 52bb943

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,52 @@ GIT_PAGER=cat git range-diff ...
719719
git --no-pager log ...
720720
```
721721

722+
### Non-interactive "Interactive" Rebases
723+
724+
AI agents cannot drive interactive editors reliably. Instead, insert a
725+
`break` as the first todo command so the rebase stops immediately, then
726+
edit the todo file directly:
727+
728+
```bash
729+
# Start the rebase, stopping before any picks execute
730+
GIT_SEQUENCE_EDITOR='sed -i 1ib' git rebase -ir <base>
731+
732+
# Find and edit the todo file with the view/edit tools
733+
git rev-parse --git-path rebase-merge/git-rebase-todo
734+
735+
# After editing the todo, continue (GIT_EDITOR=true suppresses the
736+
# editor that fixup -C and amend! commands would otherwise open)
737+
GIT_EDITOR=true git rebase --continue
738+
```
739+
740+
### Scripted Hunk Staging
741+
742+
`git add -p` is interactive by default, but its prompts follow a
743+
predictable protocol. To stage the first hunk of a file without
744+
human interaction:
745+
746+
```bash
747+
printf '%s\n' s y q | git add -p <file>
748+
```
749+
750+
The `s` splits a large hunk, `y` stages the first sub-hunk, and `q`
751+
quits. Adjust the sequence for different hunk selections (e.g.,
752+
`y y n q` to stage the first two hunks but skip the third).
753+
754+
### Finding Which Commit to Amend
755+
756+
When a working-tree change belongs in an earlier commit (an `hg absorb`
757+
workflow), use `git log -L` to find which commit last touched the
758+
relevant lines:
759+
760+
```bash
761+
git log -L <start>,+<count>:<file>
762+
```
763+
764+
This shows the full history of a line range, making it easy to identify
765+
the commit whose title you need for a `fixup!` commit. This is far more
766+
surgical than grepping through full diffs.
767+
722768
### Fixup Commits
723769

724770
Downstream patches sometimes require adjustment due to changes in the

0 commit comments

Comments
 (0)