Why is git apply not finding the file to patch in the current directory?
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.co开发者_StackOverflow社区de 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?
How do you make a diff file?
Well, this is my process on how to apply a patch. Hope it helps you
git diff --full-index <SHAsum of commit A> <SHAsum of commit B> > change.patch (full index for binary file)
git apply --check --verbose --summary change.patch (check if it is in good patch or not)
git apply --verbose change.patch
There's a flag --unsafe-paths
, see documentation, and passing it fixed it for me. According to the documentation, the flag shouldn't matter to my patch (which affected inside the git repo and inside PWD), but it did matter, so, sorry no clue what's going on exactly. You can try it too.
Another thing I recommend is to run the git diff
command from the git repo root directory (and fix arguments accordingly), which seems to give output that's better interpreted by git apply
. Then don't use --relative
; you need --unsafe-flags
.
精彩评论