5

I'm working with another developer who's relatively new. In order to allow me to do code review on her work, I had her create a branch which I can review and periodically merge if I am happy with the changes.

That branch has gotten hosed, so I just want to "reset" it, so that it's identical to the mainline, so she can start again from clean code.

I could create a new branch, but I'd like to keep the same name and avoid creating unnecessary copies.

So how do I make branch B exactly the same as branch A?

Jordan Crittenden
  • 1,010
  • 2
  • 11
  • 23

2 Answers2

5

(Simple curiosity: how has that branch been "hosed"?)

You can close the current code review branch, then start another with the same name with --force.

hg com --close-branch -m "closing"
hg branch "same_name" --force
moswald
  • 11,491
  • 7
  • 52
  • 78
  • "hosed" = She merged and had some build problems, so reverted without rollback, then committed, then later merged again and committed. So half of the changes are correct, half were reverted. I don't want to untangle it – Jordan Crittenden Oct 26 '12 at 18:29
  • Ah. We've had more than one of our branches hosed the same way. – moswald Oct 26 '12 at 19:37
1

Assuming you have reference branch A and modified branch B with changes that you want to undo:

# checkout to the head of the modified branch
hg update B --clean

# create a reverse diff between A and B and apply it to B
hg diff -r A --reverse | hg import - --no-commit

# commit changes
hg commit -m "make `hg id -r B` identical to `hg id -r A`"

You will end up with branch B identical to branch A (use hg diff -r A to make sure).

For additional points you can try to create a merge commit to explicitly mark branches as identical in the history (somehow modify commit parents?).

Generation of reverse diff is based on: Can Mercurial do a reverse-patch?

maktel
  • 1,252
  • 9
  • 7