I have a repo with two branches, main
and feature
. The output of git log --graph --format='%s %d' --all
looks like the following:
* e (main)
| * d (HEAD -> feature)
| * Merge branch 'main' into feature
| |\
| |/
|/|
* | c
| * b
|/
* a
I now want to include the commit e
on my main
branch in the merge commit on the feature
branch, so that I have the latest changes on main
, but don't have to force push if commit b
on the feature
branch is already pushed. I also don't want to have another merge commit in my history. I want my final graph to look like this:
| * d (HEAD -> feature)
| * Merge branch 'main' into feature
| |\
| |/
|/|
* | e (main)
* | c
| * b
|/
* a
I can achieve that with git rebase -i main --onto :/a --rebase-merges
and change the instructions for the interactive rebase to:
label onto
reset 9870d06 # a
pick 579c27a b
merge -C d4caa73 main # Merge branch 'main' into feature
pick f672b7f d
The problem with that though is that in the previous merge commit, I had to resolve a conflict between b
and c
, and with this approach, I would have to resolve this conflict again. Therefore, what I would really like to do is pick up the merge commit where I left off at commit c
on main
and just continue with merging e
into feature
on top of b
. Is there a way to achieve this? Perhaps there is also a way to introduce another merge commit temporarily and then squash these two merge commits afterwards?