Skip to main content

Non-interactive hunk-by-hunk and line-by-line staging for git

Project description

git-stage-batch banner

git-stage-batch

PyPI version Python 3.10+ CI License: MIT

Hunk-by-hunk and line-by-line staging for git, designed for building clean commit history.

Writing code is messy. Git history doesn't have to be.

git-stage-batch demo

During development we experiment, refactor, backtrack, and fix mistakes. If every step ends up as a commit, the history becomes noise. A curated history turns that process into a clear sequence of logical changes.

git-stage-batch helps you build that history incrementally by letting you stage changes hunk-by-hunk or line-by-line, shaping commits around meaning instead of the order the edits happened.

Features

  • Command-based workflow - Perfect for automation and AI coding assistants
  • Line-level control - Stage specific lines within a hunk for maximum granularity
  • Interactive mode - Menu-driven hunk-by-hunk workflow inspired by git add -p
  • State persistence - Resume staging across multiple invocations
  • Batch operations - Save hunks for later, organize complex changes
  • Machine-readable output - --porcelain flag for scripting
  • No dependencies - Pure Python standard library

Quick Start

# Start reviewing hunks
git-stage-batch start

# Include the selected hunk (stage it)
git-stage-batch include

# Skip it for now
git-stage-batch skip

# Discard it (remove from working tree)
git-stage-batch discard

# Stage specific lines within a hunk
git-stage-batch include --line 1,3,5-7
git-stage-batch skip --line 2,4
git-stage-batch discard --line 8-10

# Check what's been processed
git-stage-batch status

# Start fresh after committing
git-stage-batch again

Example Workflow

# You have changes in multiple files
git status
# modified:   auth.py
# modified:   config.py

# Start staging
git-stage-batch start
# auth.py :: @@ -10,5 +10,5 @@
# [#1] - old_hash_function()
# [#2] + new_hash_function()

# Include this for first commit
git-stage-batch i

# Create first commit
git commit -m "auth: Upgrade to new hash function"

# Continue with remaining changes
git-stage-batch a

Why git-stage-batch?

Similar to git add -p but more granular and flexible:

  • Line-by-line staging - Stage specific lines within a hunk
  • Interactive mode - Continuous hunk-by-hunk workflow with menus
  • Batch operations - Save hunks for later processing
  • Colored output - Clear visual distinction in your terminal
  • File operations - Stage/skip entire files at once

Interactive Mode

For a continuous hunk-by-hunk workflow:

# Launch interactive mode
git-stage-batch -i

# Navigate with single-key commands
# [i]nclude, [s]kip, [d]iscard, [l]ines, [f]ile, [a]gain, [q]uit

Machine-Readable Output

For scripting and automation, use the --porcelain flag:

# Get status as JSON
git-stage-batch status --porcelain

# Add active session status next to a __git_ps1 branch
PS1=$PS1'\r$(__git_ps1 "\n╎\e[32m%s$(git-stage-batch status --for-prompt=\|{status}\ {processed}/{total})\e[0m")\n'

# Check if a hunk exists (exit code 0/1)
git-stage-batch show --porcelain

Batch Operations

Save hunks for later processing with named batches:

# Create a new batch
git-stage-batch new feature-work --note "Refactoring work"

# List all batches
git-stage-batch list

# Annotate a batch
git-stage-batch annotate feature-work "Updated description"

# Drop a batch when done
git-stage-batch drop feature-work

Installation

# Using uv (recommended)
uv tool install git-stage-batch

# Using pipx
pipx install git-stage-batch

# Using pip
pip install git-stage-batch

Requirements

  • Python 3.10+
  • No other dependencies (pure stdlib!)

Documentation

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for:

  • Development setup instructions
  • Commit message guidelines
  • Code style conventions

License

MIT License

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_stage_batch-0.13.0.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_stage_batch-0.13.0-py3-none-any.whl (760.7 kB view details)

Uploaded Python 3

File details

Details for the file git_stage_batch-0.13.0.tar.gz.

File metadata

  • Download URL: git_stage_batch-0.13.0.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for git_stage_batch-0.13.0.tar.gz
Algorithm Hash digest
SHA256 1a152fb6780c103be22cd952a342cb1a82ebf5f136fa5bb0a2c06ead114c5874
MD5 0aca59df104a10e61a0e9a93c0e8e151
BLAKE2b-256 435639aac8d7daf066a91dde71213ff4b4140d041d2a043da3d8bbb1d944020c

See more details on using hashes here.

File details

Details for the file git_stage_batch-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: git_stage_batch-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 760.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for git_stage_batch-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94e5cde82b30f588165b4f9a76bdb1136e0388b1921abd2b7e28cc3ba35c0244
MD5 4f142d24f827fab3c1620b5a47c67efa
BLAKE2b-256 80ceaaa101401aac0573eaaf4da1a3da346fb28bbd0947051ac1fea939787b65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page