Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accidentally Working on the Wrong Named Branch in Mercurial

Tags:

mercurial

I have been making some changes to my working directory, and noticed that I have accidentally been working on the wrong branch. I have not committed anything yet, and I would like my next commit to go against another branch. What is the best way to do this?

like image 825
Joda Maki Avatar asked Feb 28 '11 17:02

Joda Maki


2 Answers

The Shelve extension can give you grief, and this can be done entirely with Mercurial commands. Krtek almost had it but he used export instead of diff. Try this:

hg diff --git > ~/saved-work.patch
hg update --clean desiredbranch
hg import --no-commit ~/saved-work.patch
like image 107
Ry4an Brase Avatar answered Nov 11 '22 19:11

Ry4an Brase


You should be able to just hg up otherbranch. It is important that you do not use the --clean option to hg up, either directly or via an alias as that will discard your uncommitted changes.

Another option is to use one of the extensions that provides hg shelve. The process would then be:

$ hg shelve --all
$ hg up otherbranch
$ hg unshelve

That will create a patch of your changes within the .hg directory, returning your working directory to a clean state, switch to the 'otherbranch', and then apply the saved patch.

like image 26
Mark Drago Avatar answered Nov 11 '22 19:11

Mark Drago