First we need to fix the V4.15.0 branch. There are two possible methods.
git revert
is the easiest way. When given a single commit id, revert
will create its reverse as a new commit in the history.
git checkout V4.15.0
git revert HEAD
If you do not want the history to show your mistake, you'll have to use push --force
to reset the history. Please note it is usually a bad practice to rewrite history in non user branches and some repository manager never allows --force
on them for that reason. But it might be acceptable in your case, verify with your workflow policies.
# checkout the original V4.15.0 branch
git checkout commit_before_mistake_V4.15.0
# we are now detached from HEAD, so checkout a new branch
git checkout -b fixed_branch
# force push, this rewrites history
git push fixed_branch:V4.15.0 --force
Now we have to move the commit to the master branch.
Fortunately, using any of the above two methods will not delete the erroneous commit. Remember its id and you can use git cherry-pick id
to add that commit to any other branch.
git checkout master
git cherry-pick id