Git apply patch fails silently (no errors but nothing happens)
Asked Answered
P

3

45

I'm trying to apply a patch, and git apply patch doesn't give me any errors:

sashoalm@SASHOALM-PC /c/Workspace/tesseract-git/api (master)
$ git apply ../../commit-d0d9477

sashoalm@SASHOALM-PC /c/Workspace/tesseract-git/api (master)
$

As you can see, no error messages are given. But when I open the history, nothing is committed, and the index is empty. It's as if I haven't issued the git apply command.

I'm at a loss how to troubleshoot this, since there no errors to Google.

Edit: I forgot to say, but I'm trying to transplant my patches from a repository of Tesseract, where I got the source without version control, created my own empty git repo, and made some commits. Later I cloned the Tesseract repository using git svn, and now I'm trying to move my patches there.

Piaffe answered 18/7, 2014 at 9:18 Comment(2)
Maybe the changes, the patch tries to apply, are already in your repository? In that case the patch would apply but nothing would change. At least that's what I think it does.Flitch
@Zeeker Not in my case - those changes were made by me, there's no way they would be in the official repo I cloned.Piaffe
R
89

I found this while googling for the issue: http://data.agaric.com/git-apply-does-not-work-from-within-local-checkout-unrelated-git-repository

git apply will fail to do anything when used within a local checkout of a git repository (other than the one for the project the patch is made for), such as if you are patching a module that is within a site that is in Git version control.

Use patch -p1 < path/file.patch instead.

Rib answered 3/12, 2014 at 22:59 Comment(5)
I was pulling my hair out trying to understand why git returns success (status 0) but does not apply patches when I try to run it from a subdirectory. Now I know that I have to always make sure that git apply is run from the root of my repository. This might be tricky in automated scripts.Titration
Thanks. I was applying git patch from a subdirectory and it was failing silently. Just had to go to root and apply patch and it was happy.Chantilly
Thanks, was equally irritated that i can't trust git apply now !Racoon
Thanks, @JustAMartin, you saved my bacon (and sanity).Pourboire
For me the solution was to call git apply in the root directory of the git repository (it was a diff from one commit to another of that same repo and I didn't call git diff in the repos root dir)Flattop
D
2

Further to B_'s answer, you might think that using git diff --no-prefix would mean you don't need to use the -p flag on patch. It appears you would be wrong, at least in the versin of patch I have here (2.5), no -p flag is not the same as -p0. -p0 works.

Denizen answered 20/11, 2018 at 14:22 Comment(0)
F
2

Run git apply with -v option to see more information from git.

   -v, --verbose
       Report progress to stderr. By default, only a message about the current patch being applied will be printed. This option will cause additional information to be reported.

In my case the patch was silently skipped because of wrong directory from where git apply was run.

Front answered 10/10, 2023 at 18:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.