I would personally recommend rewriting the history (see the answer of Useless) and telling your team. But that requires everybody to have a certain level of git knowledge. If the rewrite approach is too risky for you, here’s an alternative:
What’s happening
Whenever you merge A
into B
, git will add all the commits/changes that are reachable from A
but not B
to B
. Your revert is one of them. As you noticed, without rewriting you can’t do anything about that.
The solution
You will have to merge the revert into master. As you want keep the stuff you reverted in master, you also need an undo of that revert on master (=reachable from master). The best way to achieve that is with these commands:
git checkout -b bugfix-revert bugfix
git revert R1
git checkout master
git merge bugfix-revert
git branch -d bugfix-revert
After these commands every branch will be in the state you want it to be and you can merge bugfix again from now on. Your history will look like this:
[master] x1---x2----------------------H
\ /
[bugfix-revert] \ M''
\ /
[bugfix] y1--y2----M--y3--y4--M'--y5
As you can see, master
contains M'
, but its changes are not in H
, because M''
undid those. M'
will never be applied to master
, because it already contains it. The state bugfix
did not change, and won’t have to.