I have successfully imported patches without having conflicting changes. But when I try to import patch with conflicting changes it throws an error saying "Hunk #1 FAILED at 11.. ". There is no option to merge changes. Is there any other way to accomplish this?
Failed hunks have to be fixed manually. There should be a *.rej file with the rejected hunk from the patch. You will have to apply it manually.
see: https://www.mercurial-scm.org/wiki/HandlingRejects
The latest versions of TortoiseHg 2.1 have tools for helping you resolve rejected chunks from patches. When you apply a patch and it has rejections, for each file with rejections it asks if you want to resolve rejected chunks. If you click Yes, it shows you a screen with the content of the file (with successful chunks applied) as well as each chunk that was rejected, to allow you to manually do the changes a little easier and mark each as resolved.
The way that I sometimes handle large rejections is to rebase the patch. In TortoiseHg 1.x I could select one node, right-click on another and actually rebase patches. In TortoiseHg 2.x they have not yet added that back in, but the workaround isn't so bad. You can still rebase patches on the commandline using hg rebase
. In either case, you need the mq
and rebase
extensions enabled (and you probably already have the former enabled). This answer is not a place for teaching how to use mq
or rebase
(there are plenty of other answers and articles that do that), so I will be assuming some familiarity with them.
In both, you will need to apply the patch to the revision on which it was based (or to one where it applies cleanly or close to clean).
Commandline:
Run hg rebase -s
patchRev
-d tip
. Along with whatever other switches you want on the rebase
command.
This will bring up your 3-way merge tool to resolve conflicts, for each file.
Run hg qrefresh
to make sure the merge results are updated into the patch.
TortoiseHg UI
I prefer the latter method for the more troublesome instances because it by default prevents Mercurial from automatically resolving conflicts. It allows me to choose the order in which I resolve files and how I resolve them, showing the status of my progress with each step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With