Search code examples
mercurialbitbuckettortoisehg

A coworker commited changes to the wrong branch and pushed to the remote repository. How can this be fixed?


We are working on a project with a two-branch system (default/stable) and use a remote repository. A coworker has implemented a new feature on the wrong branch stable, and pushed the changes to the remote repository. The changes should have been made to the default branch.

Ideally, I would like to end up with the changes moved to the default branch, with no indication of the commit on the stable branch. Are we kinda screwed since it was already pushed?

I cloned the repo and tried to rollback the local copy, but that didn't have the effect I thought it would. I tried to use the rebase extension, but I don't see a way to move the commit to another branch. I tried the backout option, but that left history that I don't want.

I suppose I could do this manually by:

  1. Making a copy of the changed files
  2. Stripping the changeset from the local and remote copy
  3. Updating to the default branch
  4. Bringing the changed files back into the project
  5. Committing the changes locally
  6. Pushing the changes back to the remote repo

Is this the only way to do this?


Solution

  • If the change is public, the only way to remove all trace is to strip the change for the public repo and all clones. That could be impractical.

    To undo the changes, you'll need to graft the changeset back to default, and backout the changeset from stable:

    Example, current state:

    Current state of repository

    Commands:

    hg update default
    hg graft 3
    hg update stable
    hg backout 3
    

    Result:

    Repository after commands