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?
A patch is usually skipped when the changes it contains were already applied in the past. There are many possible reasons for this: a merge, a cherry-pick, changes operated manually or using another patch etc.
In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With