I have split a lot of work with interactive rebasing. I'm excited to try `git history split` and to have learned about it here. But the stylistic flourish makes it seem like it's been a feature for years that people just haven't moved to instead of being something shiny and new to be excited about trying.
The new `git history` command can take three verbs - fixup, reword and split. While interactive rebasing can do fixup and rewording relatively easily and the `history` variant is a slight improvement, the split sub-subcommand is really _quite_ difficult to do in other Git tooling, including interactive rebase. Before reading on, I would challenge the reader to think about how they might do it.
The answer is that you would rebase back to at least the commit you're splitting, choose 'edit' in the rebase script for that commit (pick the rest), then when the rebase stops there, `git add (-p)` the parts you want, commit, then commit the rest, then `git rebase --continue`. I would guess that maybe 5% of the readers of this paragraph would have guessed that correctly, if I'm being pretty positive.
Patrick wrote the `git history` stuff because tools like JJ and GitButler are pushing UX that makes this type of thing very easy and Git itself is struggling to catch up. Even at a fundamental level, the first versions of history were based on the sequencer code that rebase used but it couldn't do the job properly (messing with the index/workdir), so he rewrote it based on the `git replay` machinery instead (which _itself_ is still somewhat experimental).
Interestingly, it's _still_ not optimized for agents or scripting - `split` specifically needs an interactive terminal like `git add -p` does, so not many agents are good at it. I recently tried it and Claude piped `y\ny\nn` through the command, guessing at the interactive input (y, y, n) needed to stage the hunks.
The point is, interactive rebasing is a horrible solution to this problem, `git history` clearly better, at least for splitting, but really we need non-interactive solutions to problems like this so agents can do them well.
GitButler does this well because we focus specifically on it - our status command gives hunks/files ids and hunk/file movement can happen between commits so splitting is creating an empty commit and then moving the parts over - but it's surprising that nobody else builds tooling for this increasingly common use case.
I think `git history` will slowly get better at this over time, but "interactive rebasing" is a _much_ more error prone and unintuitive way to accomplish this.
If it’s for scripting why not use the lower level ‘git update-index’. Start from the original file and a patch filed, edit the patch, apply it, and then add it the modified file to the index. The patch is the container of changes in my opinion, better have the agent act on that and then apply it instead of working interactively with the work tree.
The first is that update-index only works on worktree files, so you need to be actually modifying file contents on disk and then essentially running `hash-object` on them, then `commit-tree`, etc. For an agent, each of these are tool calls and ones that they're not very good at (because nobody really does this manually).
Quick example for clarification. Let's say you want to move half of the changes of a file from one commit to another.
The ideal way would be to run something like:
`git squash <commit-a>:<hunk-id> <commit-b>`
Which could load the tree of commit-a into memory, virtually apply the hunk change to it, calculate the new tree, write it out and rebase the commits - thus moving the hunk. This is what tools like GitButler do with `but squash` etc. One command, pretty simple, all in memory and extremely fast.
The "plumbing" path you suggest would be something like:
- (record patch changes you want) - git reset HEAD~3 - (apply patches you want in commit 1) - git update-index - git commit - (apply patches you want in commit 2) - git update-index - git commit - (recreate the commits above that)
You talk about not interacting with the work tree, but `update-index` directly deals with the working directory. It's just not built for operations like this. It's built for Linus interactively building trees from contents on a filesystem.
What a tinfoil hat kind of remark. Just because you read something that you dislike that doesn't mean the LLM bogeyman is behind it.
> the split sub-subcommand is really _quite_ difficult to do in other Git tooling
Nonsense.
- copy a commit hash and start interactive rebase before that commit,
- run git checkout on that commit hash and pick the files you want to split
- run git commit,
- resume rebase.
Done.
You also have variants of this, such as doing git reset on a edit, recommitting, and resuming rebase.
> The point is, interactive rebasing is a horrible solution to this problem (...)
This is your personal and baseless opinion on the topic. Something like git history split saves you a step when compared with interactive rebase. The biggest complain you can throw at interactive rebase is that operations such as splitting commits, renaming or reordering commits, dropping commits, etc are not what you think when talking about rebasing. But that's it. I mean, if interactive rebase added a command to split commits, git history would be hard to justify.
It’s nice you’ve done this before, so have I, but until git history it remained weirdly lacking in user friendly support infrastructure compared to most “common” tasks. Git history isn’t a major improvement, but it’s an improvement on a major weak point.
It now has 5 upvotes. A long way to go to 2656 but at least it's going in the right direction.
One of SO's selling points was that outdated answers get replaced with the more modern, better ones - and it worked for many, many years.
I don't think this is description is right. What you describe as "outdated answers" are actually answers to apply up to specific releases. Just because a project launches a release that rolls out a new feature that doesn't render the old answers wrong or stale.
It was introduced in 2.54, which was in April of this year, so less than 4 months ago. Almost nobody can run this command unless they're _really_ on top of things.
It's due in part to the number of people that kept posting screenshots of their code in their question, and the number of people that couldn't search to save their life. The noise ratio on incoming questions was always ridiculous, and the number of people who don't know how to ask a technical question is staggering. I do wish they had started to ask a series of questions to people for their first 5 or 10 posts to force them to ask questions in a useful way that was conducive to getting answers. The whole site never got over being hostile to new users.
SO had a number of fundamental issues. If you found a duplicate and flagged it as such, you couldn't explain why you thought it was a dupe in the flag. This meant that "this is a different question but the answer is the same" was just tagged a dupe the same way "this is literally the identical question" was.
I stopped participating entirely after a single event. When I was moderating the moderation, and the site decided to give me a trick question to "test if I was paying attention". Yeah, no. I don't have time for that bullshit. Apparently I'm still a top 1% user, though, and I think I've gained another 8,000 or 9,000 points since I left and stopped answering at anything.
This is clearly not the case. You can make up your own programming language and feed it to an LLM and it can reason and answer questions on it.
The old ways are still the right answer for multiple reasons, such as they still clearly work with the latest release and odds are you and everyone around you is not running the latest and greatest version of git installed.
I personally sort by ‘date modified (newest first)’ on StackExchange sites.
Sites such as stack overflow would improve significantly if they actively tagged questions and answers with version numbers they would be applicable to.
Add to that, it's patch functionality isn't as robust as `git add --patch`. For example, you cannot edit a hunk, so if you intended to tease out atomic changes, you won't be able to.
- `git rebase -i`
- Change the TODO list to `edit` the chosen commit (everything else to `pick`)
- At the `edit` point:
- (simplified) `git add -p`
- `git commit`
- `git add -u`
- `git commit`
- `git rebase --continue`That "simplified" `git add -p` in the middle and that assumption that everything else not selected is the "other patch" is fine for quick splits, but there's still power user super powers in knowing the full rebase workflow and `git add -p`.
I use this only for the aforementioned purpose.
https://github.blog/open-source/git/highlights-from-git-2-54...
And discussion at the time:
jj split --interactive {ref}
`git history` was introduced as an experimental command less than 4 months ago, which means that there are essentially zero OS releases that packages a version that contains it by default. Also, if you're on OSX and run `brew install git`, it will not overwrite the Apple version that is too old to have it.
Git 2.54 was the first release with this subcommand and it is not in Xcode CLT, Debian testing, Ubuntu 26.04 - nothing. It will be "normal" in a year, but it's ridiculous to criticize SO for "old" methods of splitting long before anyone ships with it.
The right answer doesn't change over time. It can vary with the release version you are targeting.
Highly recommend trying a good GUI out, I think you would likely have similar ah-ha moments about workflow optimizations, and honestly I just cannot understand how people get by in git without a convenient way to visualize the commit tree (and yeah I know there is a decent command line treeview, but the context switching all the time in the terminal to go from viewing the tree or even the simple log to exit out and ask for commit contents just is so much more fussy and tedious).
What are people doing to workaround this? I’ve tried to ask LLMs, but the complexity is frankly a bit off putting (I don’t have the suggestions handy)
The common advice is to never have long standing branches for WIP. But if you do, squash it to have a small number of commits, then replay it on top of the default branch. The try to understand why there’s any diff or conflict (refactor, update to the design, code removal, was not merged at all,…). As I squash merge, I always remove the PR branch from the main repo. And I keep it for about a week on my local repo (In case the PR is reverted and I needed my drafting version of it).
(This is exactly how jj does it.)
If you like this kind of convenient CLI command, I would seriously recommend giving jj a try. To give you an idea, I never bothered splitting a commit in my git days. I do it almost daily with jj. Lots of other niceties that I didn't bother with in git, but routinely do in jj.
jj has fewer commands than git, yet does everything git does.
https://lwn.net/Articles/1057561/ which goes on to explain that this was the motivation for git history.
If you have any descendants of the gir history split (i.e. it's not the most recent) you'll have to do some more work (a rebase) to get back to a useful history. I think you can do this in the middle of an interactive rebase which is ok, but still not as easy.
git add -p is the real workhorse for the rebuild: s splits a hunk into smaller ones, and e lets you hand-edit the hunk when the boundary doesn't fall on clean line breaks. Stage a coherent slice, git commit, repeat until the tree is empty, then git rebase --continue. The rebase's only job is to drop you at the right spot; add -p does the actual splitting.