I want to apply a patch to a file in the current directory. The path in the patch file says just a/FILETOPATCH.something b/FILETOPATCH.something. If I use this with git apply it isn't working. The file to patch and the .patch file are in the same directory.

I tried the --directory and -p option in many variants with no success.

Using patch -p1 < patchfile.patch is working fine.

If I set an absolute path from the repository root inside the .patch file it is working with git apply as well, but there must surely a way without editing patch fieles.

This will work with git apply

diff --git a/htdocs/something/whatever/file.code b/htdocs/something/whatever/file.code
index 385f3f4..07d8062 100644
--- a/htdocs/something/whatever/file.code
+++ b/htdocs/something/whatever/file.code
...
PATCH DATA
...

But not this (this is the original)

diff --git a/file.code b/file.code
index 385f3f4..07d8062 100644
--- a/file.code
+++ b/file.code
...
PATCH DATA
...

Any ideas how to get git apply working without changing the patch files?

Edit
Report