Hg is almost committed to the wrong branch

I have a change set that is not specified. I noticed that I was in the wrong branch, so before I do this, I would like to switch to the branch on which I was going to be enabled, and then commit.

How hard is it to achieve this in Hg?

+6
source share
4 answers

If there is a linear path between the current parent version and the target revision, you can simply issue

hg update right-branch 

and Mercurial will merge the changes of your working copy into the target version.

This is done using a tool with a full merge of tools , so things like renaming are taken into account, and you get a three-way merge program in case of conflict. Shelf-based and diff-based underlays do not have this and require you to fix conflicts manually using .rej files. You can even see the current merge status with hg resolve --list and re-merge the selected files, since Mercurial will make the necessary backups for you.

If there is no linear path, you will receive this warning:

 abort: crosses branches (merge branches or use --clean to discard changes) 

Then you can get what you want by first updating back to a common ancestor and then updating it again. I am not 100% sure why we give this warning, but a search for mail list archives should give you an answer if you are interested.

+5
source

If you want to do this without expanding the shelf, do the following:

 hg diff --git > ../work_in_progress.patch hg up desired-branch hg import --no-commit ../work_in_progress.patch 

Where ../work_in_progress.patch can be any path you want (I usually store my patches just above my repository), and desired-branch is the branch you really want to apply your changes to.

Please note that any solution found starts to fall apart if the branch in which you are located and the branch you intend to use are different enough so that your patch does not apply smoothly. In this case, you start to manually resolve conflicts.

+3
source

If you use TortoiseHg, it is very easy to achieve using the THG shelf ( http://tortoisehg.bitbucket.io/manual/2.9/shelve.html ). In the commit dialog box, simply click on the β€œSlide” button (whose icon is a file with Z overlaid), then the double right arrow to postpone any changes. Close the shelf dialog box, update to the desired set of changes, open the shelf dialog box and click the double left arrow to delete them.

If you are not using THG, you can install the hgshelve extension ( https://www.mercurial-scm.org/wiki/ShelveExtension ), but I am not familiar with it.

It seems you can also achieve the same result with Mercurial Queues ( http://mercurial.808500.n3.nabble.com/Shelve-extension-td802439.html ).

+2
source

Unfortunately, Mercurial does not support racks out of the box, so you need to make a temporary commit and transfer it to the desired branch using rebase or tramsplant or run diff and apply it manually. You can also use a third-party shelf extension, see https://www.mercurial-scm.org/wiki/ShelveExtension and https://www.mercurial-scm.org/wiki/AtticExtension

+1
source

Source: https://habr.com/ru/post/897315/


All Articles