开发者

Accidentally Working on the Wrong Named Branch in Mercurial

I have been making开发者_StackOverflow社区 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?


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


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.


I don't know if it is the best solution, but you can follow these steps :

hg diff --git > modifications.patch

hg update -C the_right_branch

hg patch modifications.patch

Maybe it's better to copy modifications.patch somewhere safe, just in case.

edit: update with diff instead of export. Thanks to the commenters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜