Note: The scenario I describe here is not answered in Stack Overflow: Completely manual Mercurial merge.
I will explain my query with an example. Assume I start off a Mercurial repository to design a car:
C:\Car$ dir
Car.cpp
Car.h
I work on the design of Car for quite a while and the repository looks like:
r0-r1-...-r100-(default)
At some point in time I branch default to SolarCarBranch to work on a solar powered car in parallel:
C:\SolarCar$ dir
Car.cpp
Car.h
Solar.cpp
Solar.h
After some more time, the repository looks like:
r0-r1-...-r100-...-r200-(default)
\--r101-...-r201-(SolarCarBranch)
How do I merge SolarCarBranch back to default?
Take note of the following complications in the merge I want:
- I should be able to continue work on both default and SolarCarBranch after the merge.
- There might be fuel efficiency fixes in
Car.cppandCar.hin SolarCarBranch that I want pulled into default, however I do not want all the changes in those files. So, I want to cherry pick the changes I want to be included in default during the merge (aka manual merge). - I do not want
Solar.cppandSolar.happearing in default. The world may not yet be ready for a solar powered car. 😉
What I have learned:
- This is possible by a
hg merge SolarCarBranch - This can be achieved by setting
kdiff3.premerge=FalseinMercurial.ini - I do not know how to achieve this since
premerge=Falsestill merges/copiesSolar.cppandSolar.hinto default without asking me for permission.
You’re really close and you don’t need to resort to Transplant (yuck) or cherry picking in general. Turning off premerge is the first step, and then just remove the files you don’t want in the main branch after merging but before committing. You’ll only have to do it once.
Here’s a setup:
You can see that changeset 1 adds a file to the solar branch — a file we don’t want in default. While changeset 3 tweaks a file that also exists in main, afile, and we want to manually control whether or not that change happens.
So do
hg update default ; hg merge -r solar. The merge tool will pop up forafileand we decide line-by-line or chunk-by-chunk if we want those changes. After saving do ahg stat:And we see that solar-only is queued up for commiting in default. Just remove it (with
if).Now
hg statshows it as removed:and when we commit we’ll have what we want in the new changeset.