Suppose the following git history (in chronological order):
master [I]------------------------[M2]---[MG]---[RV]---[MG2] dev \---[D1]----------[D2]----------/ / release \---[R1]-------------------------------/ - The repo starts with an initial commit
I. - A dev branch is created with one new commit
D1. - A release branch is branched off of dev with a new commit
R1. - A new commit is added to the dev branch (
D2). - A new commit is added to the master branch (
M2). - dev is merged into master (
MG) - Uh oh! we didn't mean to do that... we revert the merge commit
RVwith-m 1to specify that master should be considered the mainline - We had meant to merge release into master, so we do that now (
MG2)
Oh no! Now the changes introduced in D1 are not present on master. I want them to be included (but I don't want D2's changes to be present). So my questions are:
- Assuming that I've just merged dev to master (
MG), is there a command that I can use in place ofgit revertso that when I merge release into master I'll still have the changes fromD1? - Suppose I've already gone ahead with a merge from dev into master and a revert, is there a command I can use in place of
git mergeso that when I merge release into master I'll still have the changes fromD1?
I'm aware that I could achieve this by doing a git reset --hard M2 on the master branch, but I want to avoid rewriting history if at all possible. It would also be great if a solution accounted for the possibility that additional "good" commits were added to the master branch between MG and RV or between RV and MG2.