Skip to content

Latest commit

 

History

History
100 lines (68 loc) · 1.91 KB

File metadata and controls

100 lines (68 loc) · 1.91 KB

git-split

Split files while preserving git blame history.

git-split restructures source files by creating temporary git branches, performing git mv operations, then merging — so every line retains its original authorship and commit history.

Installation

pip install git-split

Or for development:

git clone <repo-url>
cd git-split
pip install -e ".[dev]"

Usage

Autodetect mode (inline markers)

Add SPLIT:EXTRACT / SPLIT:ENDBLOCK markers as comments in your source file:

# Code that stays in the original file
def helper():
    pass

# SPLIT:EXTRACT:models.py
class User:
    name: str

class Post:
    title: str
# SPLIT:ENDBLOCK

def main():
    pass

Then run:

git-split source.py

Manual mode (line ranges)

git-split "source.py:10-20:new_file.py"

Options

-p, --preview      Show preview of changes
-n, --dry-run      Perform a dry run without making any changes
-y, --accept-all   Accept all changes without confirmation
-m, --message      Custom commit message

MCP Server

git-split includes an MCP server for use with LLMs:

pip install "git-split[mcp]"
git-split-mcp

MCP Tools

  • detect_blocks — Scan a file for SPLIT markers
  • preview_split — Preview how a file would be split
  • execute_split — Execute the split (requires confirm=True)

MCP Resource

  • git-split://syntax/markers — Documentation of the marker format

How It Works

  1. Parse the file and identify blocks to extract (via markers or line ranges)
  2. For each target file, create a temporary branch and git mv the source
  3. Octopus-merge all temporary branches
  4. Rename temp copies back to original filenames
  5. Overwrite each file with only its designated lines
  6. Merge back to the original branch with --no-ff
  7. Clean up temporary branches

Author

This script was created by Pavel Gurevich.

License

MIT