Git’s missing scriptable primitive
Stage the lines.
Only the lines.
Put exactly lines 12–18 and 40 in the index. No patch prompts, no hand-built diffs, no terminal choreography.
cargo install git-stage-lines
Range lab / local only
A tiny grammar with exact edges.
Positive numbers address working-tree lines. Prefix deletions with - to address their old index line numbers.
- 1
export function stage(spec) { - 2
− prompt(spec); - 3
+ const patch = build(spec); - 4
+ validate(patch); - 5
apply(patch); - 6
} - 7
+ export { stage };
Under the glaze
Git stays in charge.
The CLI uses the repository’s own filters and patch engine. Your working copy is never rewritten.
- 01
Read both sides
Compare the current index to Git’s filtered working-tree blob.
index → worktree - 02
Cut on line boundaries
Keep only the requested changed lines and their paired replacements.
12—18 · 40 - 03
Validate, then apply
Check one combined patch before atomically updating the index.
git apply --cached
No hidden semantics
Each number names one side.
| Token | Stage | Unstage |
|---|---|---|
12-18 | Working-tree lines | Current index lines |
-20--24 | Deleted index lines | Deleted HEAD lines |
| Replacement | Either side selects the paired whole-line change | |
Safety edge: if any number is unchanged, out of range, binary, or conflicted, nothing is applied.
Install / v0.1.0
One binary. Then it speaks Git.
Git automatically exposes an executable named git-stage-lines as git stage-lines.
From Cargo
cargo install git-stage-linesFrom source
cargo install --git https://github.com/B-Divyesh/sf-git-stage-linesBuilt for agents, too
A stable answer for tool calls.
Use --json directly or the included typed wrappers. No shell and no prompt parsing.
git stage-lines --json src/app.ts:12-18{
"ok": true,
"mode": "stage",
"files": ["src/app.ts"],
"changedLines": 7
}Stop editing patches by hand