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?
问题:
回答1:
Manual resolution
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.
Achieving 3-Way Merge
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 therebase
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
- Finish the patch as a normal changeset.
- Rebase that changeset onto the tip:
- Update to the tip. This is important as it used to set the target of the rebase operation.
- Right-click on the temporary changeset and select Rebase to bring up the Rebase dialog.
- Review that source and destination are correct, and click Continue. If there are merge conflicts, click on the resolved link that appears to open the Resolve dialog.
- Click Mercurial Resolve to let Mercurial try to automatically resolve some conflicts.
- For anything else that remains use Tool Resolve to bring up 3-way merge for selected files.
- Once all are resolved, click Close on the Resolve dialog.
- Click Continue and then Close on the Rebase dialog.
- Right-click on the temporary changeset now at the tip and go to Modify History > Import to MQ. Now it is a patch again.
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.
回答2:
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