]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/history: implement "split" subcommand
authorPatrick Steinhardt <ps@pks.im>
Mon, 2 Mar 2026 12:13:12 +0000 (13:13 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Mar 2026 23:09:37 +0000 (15:09 -0800)
commitd563ecec2845467880f5742e178a9723afef495a
treee97e5d235473d4faa9ba20caaf56ace6e295bac4
parent98f839425db94eb8d4c1f773e923ba1cff622d66
builtin/history: implement "split" subcommand

It is quite a common use case that one wants to split up one commit into
multiple commits by moving parts of the changes of the original commit
out into a separate commit. This is quite an involved operation though:

  1. Identify the commit in question that is to be dropped.

  2. Perform an interactive rebase on top of that commit's parent.

  3. Modify the instruction sheet to "edit" the commit that is to be
     split up.

  4. Drop the commit via "git reset HEAD~".

  5. Stage changes that should go into the first commit and commit it.

  6. Stage changes that should go into the second commit and commit it.

  7. Finalize the rebase.

This is quite complex, and overall I would claim that most people who
are not experts in Git would struggle with this flow.

Introduce a new "split" subcommand for git-history(1) to make this way
easier. All the user needs to do is to say `git history split $COMMIT`.
From hereon, Git asks the user which parts of the commit shall be moved
out into a separate commit and, once done, asks the user for the commit
message. Git then creates that split-out commit and applies the original
commit on top of it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-history.adoc
builtin/history.c
t/meson.build
t/t3452-history-split.sh [new file with mode: 0755]