I tried to apply a patch of patches (one of which essentially deletes every lines in one file and separately recreates the file with small differences and a different name – it’s a rename but more than 50% different) to a file (with
git apply --whitespace=fix --reject), but I got this error message:
Checking patch path/to/file/to/patch…
error: while searching for:
error: patch failed path/to/file/to/patch:1
error: removal patch leaves file contents
error: path/to/file/to/patch patch does not apply
I looked and the contents of the patch were very slightly different to the file being deleted (a line was moved up three, and had 3-4 characters removed), but what does the error message
removal patch leaves file contents
mean? Git knows this is a whole file deletion, but when it applies the patch there’re lines left (as in "patch leaves file contents behind")? Or that it somehow goes out of bounds (as in "patch leaves [the] file contents")?
And why can’t git figure out what to do? Git uses a similar heuristic to find file renames, I’m surprised there’s not a similar process in place. Also using
-3 fails to apply all the patches, otherwise I would have had an easier time confirming I found all the changes.
I looked and the contents of the patch were very slightly different to the file being deleted (a line was moved up three, and had 3-4 characters removed), but what does the error message mean?
The error message means that Git does not know how to apply the patch. Use your own knowledge about how software works to decide how to apply the patch yourself, and then do that.
And why can’t git figure out what to do?
Git has instructions that say "delete file X, which looks like this" but the file doesn’t look like that. Rather than blindly delete the file anyway, Git errs on the side of caution, saying: Hey, man, I’m just a dumb computer program. The file doesn’t look right to me. You’re a smart human, you figure it out.
Answered By – torek
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0