I committed and pushed some changes to the wrong branch. I found a way to fix it, but it seems overly complicated. Is this really the easiest way?
- on the branch that you made your changes, type
hg parent
- run
hg diff -r <parent> -r <with_changes> > patch.diff
hg up <proper_branch>
hg import --no-commit patch.diff
hg ci -m 'committing changes to proper branch'
hg up <bad_branch>
hg parent
to find previous changeset on this branch that is goodhg ci --close-branch -m 'closing bad branch'
hg up <last_good_changeset>
- add a space or other minor change
hg ci -m 'making tip'
hg push
Something to that effect anyway. I did it in a slightly different order; I made the good changeset the tip again, and had to do a force commit because it creates a new head, then had to run
hg heads `hg branch`
To find the bad branch again, then close it. Now it still shows the bad changeset as the “tip” because I closed it after I “re-tipped” the good branch, but when updating to that branch, I guess it takes the most recent non-closed head?
Seems like quite a ridiculous process to fix such a simple mistake.
Is there any easier way to do this? Why not?
7
I did find a cleaner solution. You don’t need to “touch” the branch to bring it back to tip, nor close off the bad branch.
Instead, just up to the bad branch, hg revert -r <last_good_commit> -a
then recommit.
Since you’re upping to the tip of the bad branch it doesn’t create a new head, and then your reverted changes get pushed to the tip instead.
Is there any easier way to do this?
Yes. hg help rebase
: rebase changeset to the new correct parent and push
PS: you have to enable Rebase extension before using command
1
hg rollback
will rollback the LAST transaction if you have not pushed. If you’ve committed or pushed work after the transaction you want to make go away, it will not work. hg help rollback
for details.
3