I might be able to explain the process a tad more clearly if I knew the branching structure, but generally you would do this:
You really only need to create a new merge between g
and i
, because as you've drawn it, none of the merges you want to remove are in the history of either g
or i
, and all relevant changes are in the history of either g
or i
(i.e. the section being removed is only merge commits[1]).
You don't want to redo all the conflict resolution, but that's ok because you already know the desired result of the merge. So what you need is to make a copy of j
whose parents are g
and i
. There are at least two ways to do that.
The most straight-forward way uses plumbing commands, so it may look less familiar.
git checkout $( git commit-tree j^{tree} -p g -p i -m "merge message here" )
git branch -f my_branch
where my_branch
is the branch you currently have at j
, and j
g
and i
are expressions that resolve to the respective commits from your diagram. (That could be commit iD (SHA) values, refs currently pointed at those commits, etc.)
Remember that the commit's parents are ordered - the second -p
option identifies the commit that will appear to have been 'merged into' the first -p
option's commit.
A different approach would be to check out g
(assuming g
should be the first commit; swap g
and i
in this procedure otherwise), and
git merge --no-commit i
git rm -rf :/:
git checkout j -- :/:
git commit -m "merge message here"
In this approach, you're initiating a new merge, clearing the work tree and index, loading the commit tree and index from the previous merge result, and then completing the merge with that content.
I find this a little more involved, and it includes an rm
command that might raise red flags if you're not confident about what's going on, but it has the advantage of sticking to commands meant for end users.
[1] I am sort of assuming that none of the merges introduce new changes (other than conflict resolution). If they do, they are what is sometimes called "evil merges"; the procedure above would still work, actually, but it would result in your new merge being an "evil merge" as well.