Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git apply skips patches

Tags:

git

patch

I'm trying to apply a patch that includes binary files with git apply but only the files are added. I tried running git apply failing.patch -v and it prints something like:

Skipped patch 'file.txt'.
Checking patch file.bin...
Applied patch file.bin cleanly.

How can I find out what's the reason of the skip? As the current message is not very enlightening.

like image 907
Iulian Onofrei Avatar asked Feb 22 '17 08:02

Iulian Onofrei


People also ask

How do patches work in git?

GIT patch or GIT diff is used to share the changes made by you to others without pushing it to main branch of the repository. This way other people can check your changes from the GIT patch file you made and suggest the necessary corrections.

What is git apply?

git apply takes a patch (e.g. the output of git diff ) and applies it to the working directory (or index, if --index or --cached is used). git am takes a mailbox of commits formatted as an email messages (e.g. the output of git format-patch ) and applies them to the current branch.


2 Answers

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.

like image 82
Iulian Onofrei Avatar answered Oct 01 '22 05:10

Iulian Onofrei


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.

like image 24
damjan Avatar answered Oct 01 '22 03:10

damjan