Why did hg rollback not work, and how do I rollback both locally and on Bitbucket?

380 views Asked by At

I use Mercurial, and I immediately push every commit to BitBucket.

I recently made a commit to my local repository, and pushed it to BitBucket via hg push. Later, I realised that I shouldn't have made that commit, so I tried:

$ hg rollback
repository tip rolled back to revision 37 (undo push-response)

But the file in Xcode did not change. I closed the Xcode window and reopened it, but no change. I tried to revert the rollback in Bitbucket, but that didn't work either:

$ hg push ssh://[email protected]/myuser/myproject
pushing to ssh://[email protected]/myuser/myproject
searching for changes
no changes found

How do I rollback, both locally and in BitBucket? I want the code to go back to the state it was in before the bad commit.

1

There are 1 answers

2
Nanhydrin On BEST ANSWER

You can't rollback in Bitbucket, you have to strip the change from the repository.
In Bitbucket, go to the repository Settings and then Strip commits. Enter the hash id of the commit and click Preview strip, then if you're happy that it's going to strip the right commit you can confirm it.

Now you can remove or edit the commit in your local copy.
hg rollback isn't recommended these days, if you can fix the commit you can use hg commit --amend to update it before pushing again.

Rollback will remove the commit and leave the changed files in an uncommitted state in your working directory. It appears from the message you got that your rollback succeeded, and I wouldn't expect the file to change in XCopy because it leaves the change in your working directory, but if you look at what the tip of the repository is now your commit should be gone and if you look at the state of your working directory you should have uncommitted changes corresponding to your unwanted change.
You should be able to hg revert any uncommitted changes you don't want.

If the commit is still there, and you want to get rid of it completely and don't want to keep the code at all you can use hg strip to remove it (you may need to activate the strip extension in the mercurial settigs first).

Mercurial - Finding and fixing mistakes

Strip extension