npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

git-patch

v0.1.4

Published

Non-interactive hunk staging for LLMs — stage, unstage, and discard git changes by hunk or line

Readme

git-patch

Non-interactive hunk staging for LLMs. Stage, unstage, and discard git changes by hunk or line — no interactive prompts required.

Every visual git tool (magit, lazygit, Fork) does hunk staging via git apply --cached, but there's no standalone CLI for it. LLMs can't drive git add -p (interactive), so they're stuck with all-or-nothing git add <file>. This tool bridges that gap.

Install

npm install -g git-patch

Or use directly with npx:

npx git-patch list

Usage

List hunks

git-patch list                    # Human-readable hunk list
git-patch list --summary          # One line per hunk (id + file/range + counts)
git-patch list --json             # Structured JSON output
git-patch list --json --summary   # Flat hunk summaries for scripts/LLMs
git-patch list --staged           # Show staged hunks
git-patch list -- src/main.rs     # Filter to specific files

Untracked files are included in unstaged output, so brand new files get hunk IDs without needing git add -N.

Each hunk gets a sequential ID. Change lines within each hunk are numbered too — these are what you use for line-level selection.

Stage hunks

git-patch stage 1                 # Stage hunk 1
git-patch stage 1,3,5             # Stage multiple hunks
git-patch stage 1-5               # Stage a range
git-patch stage 1:2-4             # Stage lines 2-4 of hunk 1
git-patch stage 1:3,5,8           # Stage specific lines of hunk 1
git-patch stage --all             # Stage everything
git-patch stage --matching "TODO" # Stage hunks matching a regex

This also works for untracked files directly; no intent-to-add prep step required.

Unstage hunks

Same selectors, operates on staged diff:

git-patch unstage 2               # Unstage hunk 2
git-patch unstage --all           # Unstage everything
git-patch unstage --matching "fn" # Unstage hunks matching regex

Discard changes

Removes changes from the working tree (destructive — requires --yes):

git-patch discard 3 --dry-run     # Preview what would be discarded
git-patch discard 3 --yes         # Actually discard hunk 3
git-patch discard --all --yes     # Discard all unstaged changes

Status

git-patch status                  # Summary of staged/unstaged/untracked
git-patch status --json           # JSON output

Selector syntax

| Selector | Meaning | |----------|---------| | 1 | Single hunk by ID | | 1,3,5 | Multiple hunk IDs | | 1-5 | Range of hunk IDs | | 1-3,7,9 | Mixed range and individual IDs | | 1:2-4 | Lines 2-4 within hunk 1 | | 1:3,5,8 | Specific lines within hunk 1 | | --all | Everything | | --matching "regex" | Hunks where any change line matches |

Line indices are 1-based and count only change lines (+/-), not context lines. This matches what you see in git-patch list output.

LLM workflow

# 1. See what changed
git-patch list --json

# 2. Stage related changes together
git-patch stage 1,3        # These two hunks are related
git commit -m "feat: add validation"

# 3. Stage the rest
git-patch stage --all
git commit -m "refactor: clean up helpers"

How it works

Under the hood, git-patch:

  1. Parses git diff output into structured hunks
  2. Reconstructs valid unified diff patches for your selection
  3. Pipes them to git apply --cached (stage), git apply --cached --reverse (unstage), or git apply --reverse (discard)

Zero dependencies — Node.js builtins only. Requires Node 22+.

License

MIT