git apply does output nothing and does not patch anything
Asked Answered
M

3

11

I am having a little trouble here with git and applying a patch.

I am trying to apply this patch: https://www.drupal.org/node/2309321

To this module: https://www.drupal.org/node/2309089

I know, that those are both Drupal links, but that is not the problem here. You can simply download the module and put the patch in the same folder. No Drupal needed for this.

For reference: I named the patch eck_test.patch.

This what I have tried so far:

git apply -v eck_test.patch

No output at all.


git apply -v --whitespace fix eck_test.patch

No output at all.


git am eck_test.patch

Patch format detection failed.


I have no idea, why this is not working.

Both line endings are the same, regarding to Sublime Text.

There are a lot of topics about this on the net, but I found none of them working for me. I hope you have some idea, because git seems like, it does not want to help me. :/

Mammilla answered 11/8, 2014 at 10:10 Comment(6)
Usually "no output" is a good thing for linux tools. Have you checked if your files were in fact patched?Quodlibet
I know, but unfortunately the files are not patched :/ I updated the title of the question, to point that out.Mammilla
Have you tried patch -p1 --dry-run < eck_test.patch? Does that show any error? You may need to adjust the level -p... to 0. If that doesn't show any error, the patch is ok. You can then remove the --dry-run to apply it.Gayl
Thanks, for the tip. But this question is not about patch, but about git apply and why it is behaving so weird. Also patch seems to be unable to create any files.Mammilla
I am seeing the same thing on a different codebase -- for me patch -p1 applies fine.Methodism
I'm getting the same thing (in a completely unrelated codebase), git apply -v shows no output and has no effect, but patch -p1 reveals some hunks fail. Why wouldn't git apply mention this?Aloha
D
4

I had the same symptoms. When I tried patch -p1 --dry-run < [patch name].patch, as suggested by @martin in a comment, it gave some helpful output: "Hunk #1 FAILED". Looking more closely at the patch, I realized that there was a conflict in the patch, which git apply had failed to report. (The patch was trying to delete a line, but the line being deleted was different in the patch vs. my working copy.) So the solution was to fix the patch.

Decemvirate answered 18/12, 2015 at 21:8 Comment(0)
B
0

I have similar problem with you in a MAC git project. It turns out the solution for me is applying the patch in the same folder (in your Git project) as the patch happens.

For example, if you do the "git format-patch" at folder \dirA\dirB in one repository, then you have to apply the patch in another repository also in \dirA\dirB. Run the "git app" at \dirA will cause the problem.

Burgin answered 6/3, 2015 at 1:36 Comment(2)
Thank you for your answer, but that does not seem to work. Also you can strip the directories in the patch down by using the "-p" parameter and you can set up the directory from which the paths in the patch my relatively be applied by using "--directory". This does not solve it for me, sorry.Mammilla
For me, it turns out it was the directory. Patch is fine being in the dir where the replacements happen, but git seems to want to apply it from repository root. Editing the patch to add a few parent directories (back up to the git repo root) worked. I didn't try --directory or -p so I don't know if they also work.Aloha
M
0

It's possible to get this problem for a silly reason, where no tweaking of the arguments to git apply will help or provide any feedback.

git show ##### -- myFile > git apply -3 --verbose

was failing silently. (as well as --reject or --check)

The fix was to notice I'd used the wrong pipe symbol by mistake, and was just writing the patch over and over to a new text file named "git":

rm git
git show ##### -- myFile | git apply -3 --verbose
Mommy answered 30/10, 2023 at 15:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.