Search code examples
mercurialrebase

Undoing a mercurial rebase


I've done a rebase on my local repository, and it's gone wrong. How do I come back from it?

Before the rebase

@  225:c5eb9b47e19a Task #1 modified due to comment by peers
|
| o  224:7a1964c6b694 WIP on Task #2 depending on Task #1
| |
| o  223:eb5a2ce5ef36 Task #1 sent for peer review
|/
o  222:d18063b01959 Remote tip

The unfortunate rebase

Coming from a git world, I'm used to rebase things. That may have been my mistake.

$ hg rebase -r224
merging some_file
3 files to edit
saved backup bundle to /path/to/repo/.hg/strip-backup/7a1964c6b694-backup.hg

After the rebase

@  224:c5eb9b47e19a Task #1 modified due to comment by peers
|
| o  223:eb5a2ce5ef36 Task #1 sent for peer review
|/
o  222:d18063b01959 Remote tip
$ hg diff
# nothing
$ hg st -amdr
# nothing
$ hg update --clean 7a1964c6b694
abort: unknown revision '7a1964c6b694'!

I'v lost my work commited as WIP on Task #2 depending on Task #1: it isn't in c5eb9b47e19a (I must have messed while merging), and the original commit is gone (is it?).

How do I cancel / revert my rebase?


Solution

  • Get "WIP on Task #2 depending on Task #1" back

    hg up 223
    hg unbundle /path/to/repo/.hg/strip-backup/7a1964c6b694-backup.hg
    

    Get opposite of "WIP on Task #2 depending on Task #1"

    hg revert --all -r 223
    hg commit -m opposite of WIP on Task #2 depending on Task #1
    

    Apply opposite of "WIP on Task #2 depending on Task #1" to undo the merge

    hg update 224
    hg rebase -r 225