Skip to main content

✂️ psplit: Split git patch files ✂️

Usage

psplit [-h. --help]
       [-c, --clean]
       [-d, --directory DIRECTORY]
       [-h, --hunks HUNKS]
       [-j, --join-character JOIN_CHARACTER]
       [-p, --parts PARTS]
       [files ...]

Positional arguments

  files                 Files to split (or split stdin if no files)

Optional arguments

  -h, --help            show this help message and exit
  --clean               Clean --directory of patch files
  --directory DIRECTORY, -d DIRECTORY
                        Output to this directory (create if needed)
  --hunks HUNKS, -u HUNKS
                        Split into parts containing this many hunks
  --join-character JOIN_CHARACTER, -j JOIN_CHARACTER
                        The character to replace / in filenames
  --parts PARTS, -p PARTS
                        Split into this many parts

How it works

psplit is a utility to split large git patch files. It is a single file with no dependencies except Python 3.9 or greater.

psplit splits its inputs by file, then each file is split into one or more patches. Each output patch file gets a unique name derived from the underlying file name.

To avoid clutter, use the --directory/-d flag, which creates a subdirectory if needed and puts the new patches in it.

If you set --parts/-p, psplit will split each file into that many parts: each file gets the same number of parts.

If you set --hunks/-u, psplit will split each file into parts containing that many hunks: larger files will get more parts.

(A hunk is a small, self-contained delta for a single text file. A patch contains zero or more files, each file containing one or more hunks.)

If neither flag is set, psplit will use the square root of the number of hunks in the file, the geometric median between all the hunks in one part and one hunk per part.

Example

$ g diff HEAD~ | psplit -d patches
Creating patches/
Writing patches/tools-linter-adapters-_linter.py.patch
Writing patches/tools-linter-adapters-_linter-__init__.py.patch
Writing patches/tools-linter-adapters-_linter-argument_parser.py.patch
Writing patches/tools-linter-adapters-_linter-block.py.patch
Writing patches/tools-linter-adapters-_linter-blocks.py.patch
Writing patches/tools-linter-adapters-_linter-bracket_pairs.py.patch
Writing patches/tools-linter-adapters-_linter-file_linter.py.patch
Writing patches/tools-linter-adapters-_linter-file_summary.py.patch
Writing patches/tools-linter-adapters-_linter-messages.py.patch
Writing patches/tools-linter-adapters-_linter-python_file.py.patch
Writing patches/tools-linter-adapters-_linter-sets.py.patch
Writing patches/tools-linter-adapters-docstring_linter.py-1.patch
Writing patches/tools-linter-adapters-docstring_linter.py-2.patch
Writing patches/tools-linter-adapters-docstring_linter.py-3.patch
Writing patches/tools-linter-adapters-set_linter.py-1.patch
Writing patches/tools-linter-adapters-set_linter.py-2.patch
Writing patches/tools-test-test_docstring_linter.py.patch

How to install

Either use pip: python -m pip install psplit. Or simply download the file psplit.py and put it into your path.

Other alternatives

https://manpages.ubuntu.com/manpages/xenial/man1/splitpatch.1.html didn't work well for large files and isn't available on Mac OS

https://pypi.org/project/splitpatch/ is complicated and very new

Metadata

Release files for psplit 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for psplit 1.2.0
File Size Uploaded
psplit-1.2.0.tar.gz 36.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for psplit 1.2.0
File Interpreter ABI Platform
psplit-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.7 kB

Release files / psplit-1.2.0.tar.gz

Download URL psplit-1.2.0.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
30ce3f877a54704349a6ae6d94610d6cf4dc325199a2fd9efcbbe2799868d0f2
BLAKE2b-256 checksum
How to use checksums
091df14fb63cb76710bc9a198e16c36113ac155670d93e00cc5252c202ed58c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / psplit-1.2.0-py3-none-any.whl

Download URL psplit-1.2.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4efd3e6b0d962f786d938818f068d2a5804bab19be5cd031dd70a96b577e0b1
BLAKE2b-256 checksum
How to use checksums
742664c144fc34850d683a2aa9811bf870b740734daa8abe6f962717c191af45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page