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
Three thin porcelain slabs separated by a blue glass seam, representing working tree, selected lines, and Git index layers
working treeselected rangeindex
One atomic patchZero promptsZero telemetryMIT licensed

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.

Try 3-4,7 or a deletion such as -2.

Your command git stage-lines src/app.ts:3-4,7
working treeselected lines are glazed blue
  1. 1export function stage(spec) {
  2. 2−  prompt(spec);
  3. 3+  const patch = build(spec);
  4. 4+  validate(patch);
  5. 5   apply(patch);
  6. 6}
  7. 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.

  1. 01

    Read both sides

    Compare the current index to Git’s filtered working-tree blob.

    index → worktree
  2. 02

    Cut on line boundaries

    Keep only the requested changed lines and their paired replacements.

    12—18 · 40
  3. 03

    Validate, then apply

    Check one combined patch before atomically updating the index.

    git apply --cached

No hidden semantics

Each number names one side.

Line numbering in stage and unstage modes
TokenStageUnstage
12-18Working-tree linesCurrent index lines
-20--24Deleted index linesDeleted HEAD lines
ReplacementEither 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-lines

From source

cargo install --git https://github.com/B-Divyesh/sf-git-stage-lines

Built for agents, too

A stable answer for tool calls.

Use --json directly or the included typed wrappers. No shell and no prompt parsing.

Command
git stage-lines --json src/app.ts:12-18
Result
{
  "ok": true,
  "mode": "stage",
  "files": ["src/app.ts"],
  "changedLines": 7
}

Stop editing patches by hand

Make the index exact.

View source on GitHub