Reputation: 3419
Our branching model says that on master
branch should be the current production state.
Accindently a develop version was merged from developed
into master
and pushed by one of our new colleages. So on master
there's not our production state any more. I want to revert this to apply a hotfix but I fail.
To know all commits I first pulled the current master
:
git checkout master
git pull
Then, like said in this thread, I try to reset my local master
using
git reset --hard <versiontag>
git push --force origin master
But the forced push is rejected because the are "future" commits.
Total 0 (delta 0), reused 0 (delta 0)
To [URL OF MY REPO]
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[URL OF MY REPO]'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Yeah I know that there are commits. And I want to remove them from master
because they don't belong there (yet, until develop
is meant to be merged into master
)
How can I successfully revert my master branch to a current tag and then push this to remote or asked in another way - how can I get rid of the wrong merged commits in my master
branch?
Upvotes: 2
Views: 6198
Reputation: 9533
If you want to do a reset
and push --force
you need to change the settings on your sever. On a plain git server, make sure that the following config options are not set:
receive.denyNonFastForwards
receive.denyDeletes
On other servers, e.g. github, gitlab, bitbucket, this can be done through the web interface.
Your other options is to create a new commit that reverts the changes you don't want. git revert
will assist you in doing this. This would be preferable if other people have already pulled the commits you want to revert.
Upvotes: 4