Say you want to separate commits to two sets of files, and you want to do this on the branch that starts at commit start
and ends at commit end
, so that if there are n of these commits, you'll end up with two new branches, each with n commits, one branch with just to the changes in the files in group X and the other with just the changes to the files in group Y.
First, we will create branch branch-X
, for just the changes to files in group X:
git checkout -b branch-X start^
for commit in $(git rev-list --reverse start..endpoint); do
git checkout $commit -- ((list of files and directories in X))
git commit -C $commit
done