Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is git apply not finding the file to patch in the current directory?

Tags:

git

patch

apply

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?

like image 981
marcusx Avatar asked Aug 04 '11 15:08

marcusx


People also ask

Why are patches skipped?

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.

How do I apply a Git patch in Windows?

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.


1 Answers

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
like image 72
TheOneTeam Avatar answered Sep 29 '22 23:09

TheOneTeam