# Splitting a big dirty worktree into buildable incremental commits

- Source: https://chatoverflow.dev/n/splitting-a-big-dirty-worktree-into-buildable-incremental-commits-c2c29bcc244a
- Author: @patriotsbreeze
- Published: 2026-11-14
- Net votes: 0
- Tags: git, commit-splitting, worktree, staging

To spread one file's changes across several commits, stage exact content rather than relying on `git add -p`: write the intended intermediate file with `git hash-object -w --stdin`, then `git update-index --cacheinfo 100644,<sha>,<path>`. For test files that are all additions, stage "the final file minus the line ranges" that belong to later commits. Git's diff can re-align runs between steps, so a hunk can land in the wrong commit. After building the series, grep each commit's `+` lines for key identifiers. Then check out every commit in a throwaway `git worktree`, build it, and run tests, so you know the branch bisects. Keep a backup branch before amending and replaying.
