[PR #24] feat: add commit splitting feature for cleaner git history #25

Open
opened 2026-02-27 19:20:57 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/f/git-rewrite-commits/pull/24

State: open
Merged: No


feat: add commit splitting feature for cleaner git history

Summary

This PR adds a new --split option that allows users to split large commits into smaller, more focused commits for cleaner git history and easier rollbacks.

The feature uses AI to analyze commit diffs and suggest logical splits based on:

  • Different files serving different purposes (source vs tests vs config)
  • Different types of changes (feature + refactor + docs)
  • Unrelated functionality grouped together

Key additions:

  • New --split flag to enable commit splitting mode
  • New --max-splits option to limit splits per commit (default: 5)
  • AI-powered analysis to determine if/how commits should be split
  • Automatic backup branch creation before splitting
  • Dry-run support to preview splits without applying
  • Documentation in README with usage examples

Review & Testing Checklist for Human

  • Test the performCommitSplit method with real commits - This method performs destructive git operations (git reset --soft, git checkout, git cherry-pick). Verify the error recovery works if something fails mid-split.

  • Test non-HEAD commit splitting - The cherry-pick logic for commits after the split target could fail with merge conflicts. Verify the warning message is appropriate and the repo isn't left in a broken state.

  • Verify AI JSON parsing - The code expects specific JSON structure from the AI. Test with both OpenAI and Ollama to ensure responses parse correctly. Edge cases: malformed JSON, missing fields, markdown-wrapped responses.

  • Test with special characters in filenames - The git add "${file}" command may have issues with unusual filenames.

Recommended test plan:

  1. Create a test repo with a few multi-file commits
  2. Run npx git-rewrite-commits --split --dry-run to preview
  3. Run npx git-rewrite-commits --split on a feature branch
  4. Verify the backup branch was created
  5. Check git log --oneline to confirm splits look correct
  6. Test recovery by resetting to backup branch

Notes

  • This feature rewrites git history, so all the existing safety warnings apply
  • The implementation processes commits from newest to oldest to minimize rebase complications
  • Sensitive data redaction is applied before sending diffs to AI providers

Link to Devin run: https://app.devin.ai/sessions/cdf71c5996d741918aff6b5f70f2bf62
Requested by: Fatih Kadir Akın (fatihkadirakin@gmail.com) / @f

**Original Pull Request:** https://github.com/f/git-rewrite-commits/pull/24 **State:** open **Merged:** No --- # feat: add commit splitting feature for cleaner git history ## Summary This PR adds a new `--split` option that allows users to split large commits into smaller, more focused commits for cleaner git history and easier rollbacks. The feature uses AI to analyze commit diffs and suggest logical splits based on: - Different files serving different purposes (source vs tests vs config) - Different types of changes (feature + refactor + docs) - Unrelated functionality grouped together Key additions: - New `--split` flag to enable commit splitting mode - New `--max-splits` option to limit splits per commit (default: 5) - AI-powered analysis to determine if/how commits should be split - Automatic backup branch creation before splitting - Dry-run support to preview splits without applying - Documentation in README with usage examples ## Review & Testing Checklist for Human - [ ] **Test the `performCommitSplit` method with real commits** - This method performs destructive git operations (`git reset --soft`, `git checkout`, `git cherry-pick`). Verify the error recovery works if something fails mid-split. - [ ] **Test non-HEAD commit splitting** - The cherry-pick logic for commits after the split target could fail with merge conflicts. Verify the warning message is appropriate and the repo isn't left in a broken state. - [ ] **Verify AI JSON parsing** - The code expects specific JSON structure from the AI. Test with both OpenAI and Ollama to ensure responses parse correctly. Edge cases: malformed JSON, missing fields, markdown-wrapped responses. - [ ] **Test with special characters in filenames** - The `git add "${file}"` command may have issues with unusual filenames. **Recommended test plan:** 1. Create a test repo with a few multi-file commits 2. Run `npx git-rewrite-commits --split --dry-run` to preview 3. Run `npx git-rewrite-commits --split` on a feature branch 4. Verify the backup branch was created 5. Check `git log --oneline` to confirm splits look correct 6. Test recovery by resetting to backup branch ### Notes - This feature rewrites git history, so all the existing safety warnings apply - The implementation processes commits from newest to oldest to minimize rebase complications - Sensitive data redaction is applied before sending diffs to AI providers Link to Devin run: https://app.devin.ai/sessions/cdf71c5996d741918aff6b5f70f2bf62 Requested by: Fatih Kadir Akın (fatihkadirakin@gmail.com) / @f
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-rewrite-commits#25
No description provided.