I have refactored a file by splitting into two files in one git branch, and someone else has made a different change to the original file on another git branch. This has produced a merge conflict in git when I tried to merge the second git branch into the first (which I did using magit). I have configured git to produce a 3-way diff surrounded by conflict markers in the file, and I have used C-c ^ = > to diff the original contents of the file and the second branch changes, which produces a vc-diff buffer.

How can I apply this vc-diff buffer to the second file, not the first file - either one hunk at a time, or all at once? I don't mind which way it is done, but I would prefer to do it one hunk at a time. (Bearing in mind that the line numbers will probably be different, but the surrounding text will be largely the same.)

1 Answer 1


Use C-c c-e in the vc-diff buffer to apply the diff to a file. Enter the target filename and press RET. This will launch ediff and attempt to apply the patch.

For me, the patch applied successfully without any hitches, so I just needed to press n a few times in the ediff frame to review the result, and then q to quit the ediff session.

Then return to the buffer for the first file and resolve the original conflict (in my case, by simply accepting my changes, as I had applied the changes from the other branch to the other file).

  • If this resolves your problem, please accept your own answer so we can mark the post as done.
    – Dan
    Commented Jan 18, 2018 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.