It is clear to me, based on your question, that you want the commit sequence to read:
... <- C1 <- new-C4 <-- branch
(remember, the arrows always point towards the past history, not forward into the future).
It's not clear to me whether you want your new commit (which I call new-C4
above) to keep the source the way it is in the old C4
, or whether you want to discard all changes made in C2
and C3
while keeping just the changes made in C4
.
You can achieve the latter result using git rebase
, but keep in mind the usual caveat that you should never rebase a published commit. To make this happen, simply run:
git rebase -i HEAD~4
This will bring up an editor session where you can keep or discard specific commits. See the answer linked in Martin Konecny's comment, or Barry Gackle's answer.
If you want to keep the changes introduced by C2
and C3
while discarding the commits themselves, then git reset --soft
followed by git commit
is the correct method. See VonC's answer here.