I want to remove a specific commit, C, in git history, as well as some single-commit-merges.
The history looks like this. In this example, I want to remove the single-commit-merge m6
and a problematic commit C
.
---m0-------------------m1---m2---m3-------------m4---m5----m6---m7---(...)
\ / \ / \ /
b0---b1---b2---b3 b4--(C)--b5 b6
I want to wind up with this (changes highlighted):
vv
---m0------------------m1---m2---m3---------m4---m5---b6---m7---(...)
\ / \vvvvvvv/ ^^
b0---b1---b2---b3 b4---b5
^^^^^^^
If I use "git rebase -i" to excise C
and b6/m6
, this works, but I get:
---m0---b0---b1---b2---b3---m1---(...)---
and the history is flattened. I want to preserve the entire structure. Conversely, if I run with the --preserve-merges
flag, then I get:
error: Commit <sha-1 corresponding to m6> is a merge but no -m option was given.
fatal: cherry-pick failed
Could not pick <sha-1 corresponding to m6>
and I can't remove b6/m6
(although I can remove C).
What's the right way to wind up with the desired result? I'm using git 1.8.4, if that matters.
(Note that the other questions on StackOverflow that I perused don't seem to account for this very specific case, so as nearly as I can tell, this is not a duplicate question.)