git: How to apply a conflicting patch?

Viewed 1577

I've got a patch that i would like to apply to my local tree. It's generated using git format-patch. It contains some conflicts, so I use the following to apply it:

$ git apply --3way mypatch.patch

This way, when I apply it, I can open the files that failed to merge, and to so by hand. However, once I have done that, I would like to "finish" applying the patch - I mean, I'd like to tell git "ok, I've finished manually resolving the conflicts - now go ahead and apply this patch with the commit message as it is in the patch, and the author that is specified in the patch".

However it seems that once there's a merge conflict, git just gives up and leaves everything to you. Is there a way to tell git, "Hey, for this commit, please take the commit message and authorship details from this patch"? Or a way to tell git, "You can continue the patch application process as normal"?

1 Answers

Start with git am instead of git apply. Then use git am --continue at the point you've reached.

Longer

The git apply command applies a patch but never makes a commit. So, whether or not it stops with a conflict, its job is now done: it would stop even if there weren't a conflict. It does not make a commit and it therefore does not use the authorship and message from any patch.

The git am (Apply Mailbox) command applies one or more patches that are stored in "mailbox format"—which includes patches generated by git format-patch—and then does make a commit: one commit for each patch. The authorship and message come from the mailbox-format patch.

When git am stops with a conflict, and you do the merge, the git am is still pending. You can complete this particular patch with git commit or resume the entire pending git am sequence with git am --continue.

Related