Git apply skips patches

If you use the --directory option to "git apply":

--directory=<root>

that path is RELATIVE TO THE BASE DIRECTORY (the one containing ".git"), not relative to the current working directory. You cannot use an absolute path either.

This is completely undocumented and took me hours to discover.


Suffering this issue whilst attempting to port changes across projects. git apply seems to ignore any directory names on the patch file paths, also it refuses to apply if the Index line does not match a file hash in the target repository. I had better success using these options (of which --no-index seems to be undocumented):

git apply --verbose --no-index --directory {subdir} {patch-file} 

I found out the problem by running patch -p1 < failing.patch which printed:

can't find file to patch at input line 5

and reminded me that I was not in the root directory.

I can't understand why no one had asked this before and why is the verbose message not verbose.

Also, not even the official documentation mentions skipping and possible causes.

Tags:

Git

Patch