Mercurial: how to merge with manual control over changes and files?

Note. The script that I am describing here does not respond to Stack Overflow: a fully manual Mercurial merge .

I will explain my request with an example. Suppose I start creating a Mercurial repository for car design:

C:\Car$ dir Car.cpp Car.h 

I have been working on car design for quite some time, and the repository is as follows:

 r0-r1-...-r100-(default) 

At some point in time, I am debugging by default on SolarCarBranch for parallel operation on a car with a solar battery:

 C:\SolarCar$ dir Car.cpp Car.h Solar.cpp Solar.h 

After some time, the repository looks like this:

 r0-r1-...-r100-...-r200-(default) \--r101-...-r201-(SolarCarBranch) 

How to merge SolarCarBranch back to default ?

Note the following merge complications that I want:

  • After the merge, I have to continue working with the default and SolarCarBranch .
  • In Car.cpp and Car.h may be fuel economy corrections in SolarCarBranch , which I want to use in the default , however I do not want all changes to these files. So, I want the cherry to choose the changes that I want to include in the default during the merge (for example, manual merge).
  • I do not want Solar.cpp and Solar.h in default . Perhaps the world is not yet ready to use solar energy .; -)

What I learned:

  • It is possible with hg merge SolarCarBranch
  • This can be achieved by setting kdiff3.premerge=False in Mercurial.ini
  • I don’t know how to achieve this, since premerge=False still merges / copies Solar.cpp and Solar.h in by default , without asking me for permission.
+4
source share
2 answers

You are really close, and you do not need to resort to transplantation (yuck) or cherry picking in general. Disabling premerge is the first step, and then just delete the files you don't want in the main branch after merging, but before committing. You will need to do this only once.

Here's the setting:

 o changeset: 3:343d531512a3 | branch: solar | tag: tip | parent: 1:cb26642f8db5 | user: Ry4an Brase < ry4an@msi.umn.edu > | date: Wed Mar 10 11:16:48 2010 -0600 | files: afile | description: | solar-change | | | @ changeset: 2:c5d14e34db07 | | parent: 0:56465175b2fc | | user: Ry4an Brase < ry4an@msi.umn.edu > | | date: Wed Mar 10 11:05:44 2010 -0600 | | files: other-main-file | | description: | | moremain | | | | o | changeset: 1:cb26642f8db5 |/ branch: solar | user: Ry4an Brase < ry4an@msi.umn.edu > | date: Wed Mar 10 11:04:32 2010 -0600 | files: solar-only | description: | solar-initial | | o changeset: 0:56465175b2fc user: Ry4an Brase < ry4an@msi.umn.edu > date: Wed Mar 10 11:04:14 2010 -0600 files: afile description: initial 

You can see that set of changes 1 adds a file to the solar branch - a file that we do not want by default. While changeet 3 modifies the file, which also exists in main, afile, and we want to manually control whether this change occurs.

So hg update default ; hg merge -r solar hg update default ; hg merge -r solar . A merge tool will appear for afile , and we decided that if we want these changes, we will choose line by line or chunk-by-chunk. After saving, run hg stat :

 % hg stat M afile M solar-only 

And we see that only solar energy is queued for default. Just delete it (using if ).

 % hg rm -f solar-only 

Now hg stat shows it as remote:

 % hg stat M afile R solar-only 

and when we commit, we get what we want in the new set of changes.

+5
source

Your first condition, to continue working on both branches, is simply not closing the branch (what do you do with the --close-branch option before hg commit ).

You can alternate a set of changes to merge with Transplant Extension . This will allow you to select only specific change groups to merge into a default value.

The third condition is satisfied that provided that you do not mix changes with both your ordinary car and your solar-powered car in the same commit, you can pull revisions from the solar branch to worry about mixing your types of cars with impunity.

You might want to take a look at the flags of the internal options to combine the configuration files .

+2
source

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


All Articles