I was working on my local branch doing some changes and when I finished I pushed everything to the remote brach. Before merging the branch with develop I thought I should do a rebase cos the other guys had merged a lot of their code there. When I did the rebase and resolved some conflicts I pushed to the remote branch. Unfortunately the way I resolved the conflicts was wrong so now I need to go back before the rebase happened and also update the remote branch to the new state.
What I tried
Reset the head
git reset --hard HEAD@{x} //where x is the head just before the rebase
This works and reverts the changes on my local branch but then I don't know what to make the remote branch update to that since it doesn't create a new commit that can be pushed to the remote.
You should not rewrite the history of remote repositories because if
not only would you have the issue of having to fix the mess but everybody else who pulled the changes. So unless you can be sure that nobody pulled it, don't do a force-push.
Instead you should revert the commit using either
>> git revert HEAD@{y} # where HEAD@{y} is the faulty commit
if only one commit was messy, in case of a merge.
In case of a rebase that transplatend several commits onto the master branch you need to do
>> git revert --no-commit HEAD
>> git revert --no-commit HEAD~1
>> git revert --no-commit HEAD~2
...
>> git revert --no-commit HEAD@{x}
>> git commit -m "Sorry folks for the big mess I made"
Where all the HEAD~y
are the commits in between HEAD@{x}
and HEAD
.
This will effectively undo all affected commits in a single big commit.