First, ensure that the commits to be replayed are backed up. If possible, push them to a local/not public mirror.
I will assume that your current branch is called B1.
Then it's pretty straightforward, and there are a few equivalent solutions
git checkout -b B2 c3 # get to the point to be amended
git reset HEAD~ # this will leave the c3 commit changes uncommitted
git add a # add changes in file a
git commit # this is your c3' commit
git add b # add changes in file b
git commit # this is your c4' commit
git cherry-pick c4 c5 # pick the other commits - can be done with rebase --onto too
git diff --name-status B1 # ensure things are the same
It is also possible to do it with the rebase --interactive
command, like:
git rebase --interactive c2
# here, mark c3 as 'edit'
# then, save
# you will have shell control in c3, then do as in the previous example:
git reset HEAD~
git add a
git commit
git add b
git commit # this is probably not necessary, haven't tried
git rebase --continue
# again, ensure things are the same, but now we are in B1 so
# we compare with the previous commit
git diff --name-status c5