You need to first clone the repository on your local system (you can get the repo URL in SSH or HTTPS format from the "Overview" page of the repository in Bitbucket):
git clone [email protected]:my/repo.git
-or-
git clone https://[email protected]/my/repo.git
git checkout master
.. then revert the most recent commit. First list the available commits with:
git log
.. then select the commit before the merge:
git reset --hard 72ead1c4c1778c23c277c4f15bbb68f3bb205f54
.. where the hash is the hash of the commit before the merge (from the log). Finally, force-push the changes back to Bitbucket, overwriting history.
git push -f
Naturally if the repo is shared, and its other users have pulled your most recent commit and built atop it, they won't be happy. So in that case be sure to notify everybody of what you're doing.
revert
, as mentioned in the other answers is another option; it keeps the commit you made, but modifies the repository further (with a new commit) in such way that it undoes the changes you made. Whether you want to use revert
depends on whether you want the information in your commit to remain in the repo history or not.
For more detail on undoing changes in git, see a good tutorial page by Atlassian.
git revert
to undo a merge (using the-m
option):git revert --help
says: Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want. -> So ifrevert
ing the merge needs to be undone, the solution is not to merge the previously merged (and then reverted) branch again but to revert the revert commit. – Headley