mirror of
https://github.com/git-for-windows/git.git
synced 2026-05-10 01:36:19 -05:00
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
This commit is contained in:
46
AGENTS.md
46
AGENTS.md
@@ -719,6 +719,52 @@ GIT_PAGER=cat git range-diff ...
|
||||
git --no-pager log ...
|
||||
```
|
||||
|
||||
### Non-interactive "Interactive" Rebases
|
||||
|
||||
AI agents cannot drive interactive editors reliably. Instead, insert a
|
||||
`break` as the first todo command so the rebase stops immediately, then
|
||||
edit the todo file directly:
|
||||
|
||||
```bash
|
||||
# Start the rebase, stopping before any picks execute
|
||||
GIT_SEQUENCE_EDITOR='sed -i 1ib' git rebase -ir <base>
|
||||
|
||||
# Find and edit the todo file with the view/edit tools
|
||||
git rev-parse --git-path rebase-merge/git-rebase-todo
|
||||
|
||||
# After editing the todo, continue (GIT_EDITOR=true suppresses the
|
||||
# editor that fixup -C and amend! commands would otherwise open)
|
||||
GIT_EDITOR=true git rebase --continue
|
||||
```
|
||||
|
||||
### Scripted Hunk Staging
|
||||
|
||||
`git add -p` is interactive by default, but its prompts follow a
|
||||
predictable protocol. To stage the first hunk of a file without
|
||||
human interaction:
|
||||
|
||||
```bash
|
||||
printf '%s\n' s y q | git add -p <file>
|
||||
```
|
||||
|
||||
The `s` splits a large hunk, `y` stages the first sub-hunk, and `q`
|
||||
quits. Adjust the sequence for different hunk selections (e.g.,
|
||||
`y y n q` to stage the first two hunks but skip the third).
|
||||
|
||||
### Finding Which Commit to Amend
|
||||
|
||||
When a working-tree change belongs in an earlier commit (an `hg absorb`
|
||||
workflow), use `git log -L` to find which commit last touched the
|
||||
relevant lines:
|
||||
|
||||
```bash
|
||||
git log -L <start>,+<count>:<file>
|
||||
```
|
||||
|
||||
This shows the full history of a line range, making it easy to identify
|
||||
the commit whose title you need for a `fixup!` commit. This is far more
|
||||
surgical than grepping through full diffs.
|
||||
|
||||
### Fixup Commits
|
||||
|
||||
Downstream patches sometimes require adjustment due to changes in the
|
||||
|
||||
Reference in New Issue
Block a user