I am not sure how to fix a situation with commits that should not have been merged into the master
branch. I am not well versed in git and have been mostly using the Visual Studio controls for it.
A while ago I merged a bunch of feature branches into develop
branch. However, I was not supposed to do that yet. Recently, a bug in the application needed fixing. So, I branched out of develop
, fixed it, and merged back into develop
. Then, I merged develop
into master
so that I can release the bug fixes.
After doing that, I realized I had forgotten about those feature branches that aren't to be released yet and now they are in master
along with the bug fixes. It's around 200 commits that need to be reverted, so I don't want to do them one by one. Once I revert them, I'd eventually need to undo the reverts as well so I can release those features.
I first tried to undo changes up to a specific commit by doing Reset > Delete Changes (--hard)
, but since the changes are pushed to the remote repository, they just reappear as incoming changes.
Then I looked up a way to revert multiple commits and tried reverting a range:
git revert --no-edit <first_bad_commit-id>..<last_bad_commit-id>
But I am getting the error:
error: commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is a merge but no -m option was given.
fatal: revert failed
Found this post about what is -m
and how to use it, but everywhere I read I just can't comprehend how to use -m
and why can't I revert merges. This is probably due to my minimal interaction with git command-line.
So, I have a range containing 200 commits I don't need that are sandwiched between commits I need. How do I undo those 200 commits?
I'd also be satisfied with a solution of undoing all the latest commits up to a specific commit. It would be quick to re-add the code for bug fixes.