I have a certain patch called my_pcc_branch.patch.
When I try to apply it, I get following message:
$ git apply --check my_pcc_branch.patch
warning: src/main/java/.../AbstractedPanel.java has type 100644, expected 100755
error: patch failed: src/main/java/.../AbstractedPanel.java:13
error: src/main/java/.../AbstractedPanel.java: patch does not apply
What does it mean?
How can I fix this problem?
Johannes Sixt from the msysgit@googlegroups.com mailing list suggested using following command line arguments:
git apply --ignore-space-change --ignore-whitespace mychanges.patch
This solved my problem.
git apply --reject --whitespace=fix mychanges.patch
worked for me.
When all else fails, try git apply
's --3way
option.
git apply --3way patchFile.patch
--3way
When the patch does not apply cleanly, fall back on 3-way merge if the patch records the identity of blobs it is supposed to apply to, and we have those blobs available locally, possibly leaving the conflict markers in the files in the working tree for the user to resolve. This option implies the --index option, and is incompatible with the --reject and the --cached options.
Typical fail case applies as much of the patch as it can, and leaves you with conflicts to work out in git however you normally do so. Probably one step easier than the reject
alternative.
This command will apply the patch not resolving it leaving bad files as *.rej
:
git apply --reject --whitespace=fix mypath.patch
You just have to resolve them. Once resolved run:
git -am resolved
It happens when you mix UNIX and Windows git clients because Windows doesn't really have the concept of the "x" bit so your checkout of a rw-r--r--
(0644) file under Windows is "promoted" by the msys POSIX layer to be rwx-r-xr-x
(0755). git considers that mode difference to be basically the same as a textual difference in the file, so your patch does not directly apply. I think your only good option here is to set core.filemode
to false
(using git-config
).
Here's a msysgit issue with some related info: http://code.google.com/p/msysgit/issues/detail?id=164 (rerouted to archive.org's 3 Dec 2013 copy)
Try using the solution suggested here: https://www.drupal.org/node/1129120
patch -p1 < example.patch
This helped me .
In my case I was stupid enough to create the patch file incorrectly in the first place, actually diff-ing the wrong way. I ended up with the exact same error messages.
If you're on master and do git diff branch-name > branch-name.patch
, this tries to remove all additions you want to happen and vice versa (which was impossible for git to accomplish since, obviously, never done additions cannot be removed).
So make sure you checkout to your branch and execute git diff master > branch-name.patch
I have found this link
I have no idea why this works but I tried many work arounds and this is the only one that worked for me. In short, run the three commands below:
git fsck --full
git reflog expire --expire=now --all
git gc --prune=now
来源:https://stackoverflow.com/questions/4770177/git-patch-does-not-apply