简体   繁体   中英

How to resolve git am's "patch does not apply" as a merge conflict?

I'm looking to move some commits from one repository to another, and I'd like to maintain the original commits, date and commit messages and all, rather than squashing the whole thing together. git format-patch master got me that, making one .patch file per commit, but I'm having some trouble applying them (I'm stuck on the first commit).

git apply <patch file name> applies the changes cleanly, with no conflicts or anything, but of course it doesn't create the commit I'd like.

git am --committer-date-is-author-date -3 < <patch file name> , on the other hand, fails with no clear way to resolve it:

Applying: <original commit message>
error: patch failed: war/WEB-INF/web.xml:162
error: war/WEB-INF/web.xml: patch does not apply
<more files listed, all of them ones that I've modified in the commit; newly created files are not listed>
error: Did you hand edit your patch?
It does not apply to blobs recorded in its index.
hint: Use 'git am --show-current-patch' to see the failed patch
Using index info to reconstruct a base tree...
M       war/WEB-INF/web.xml
Patch failed at 0001 <commit message>
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

After running this, there are no changes in my working copy or staged. I'd have expected to get changed files with merge conflict style marks ( <<<<<<<< and >>>>>>>> ), since I used the -3 flag, but I don't even have that.

Is there a way to run git am to get what I'm after, or should I use git apply and make new commits?

You can try --reject . It applies the parts of the patch that are applicable, and leave the rejected hunks in corresponding *.rej files. It helps when -3 doesn't work well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM