5

I have to apply a patch to my repo and am running

git apply --directory=$PWD xxxxx.patch

For reasons I won't go into, I cannot use git am in this instance, and I need to use the directory flag.

git tells me:

$> git apply --directory=$PWD xxxxx.patch
code1/xxxxx.patch:337: trailing whitespace.
         < one partial line of code >
warning: 1 line adds whitespace errors.

I have read that the whitespace warning is nothing serious and should not stop git from applying the patch. However, whatever the reason, git is not applying the patch. None of the current files in the repo are changing. Any idea what to do about this?

4
  • After git apply produces this warning, git status shows no changes ready to be added? That seems odd. Commented Aug 3, 2017 at 17:25
  • @torek git status displays a line listing that patch but at the end it says "nothing added to commit". Just for grins I tied git commit after the apply and got nothing added to commit again. And inspection of the files shows that no changes have been made. Commented Aug 3, 2017 at 17:28
  • The only thing I can think of here is that for some reason git apply thinks none of the file names go with your files. Note the sentence early on in the documentation: "When running from a subdirectory in a repository, patched paths outside the directory are ignored." Maybe you want to leave out --directory=$PWD if you've already cd-ed into the sub-directory, or maybe you just need to run it from the top level (and not use $PWD here). Commented Aug 3, 2017 at 18:03
  • @torek Your second suggestion, do from top level and leave out $PWD, did the trick. If you want to turn it into an official answer, I'll give you an accept. Thanks! Commented Aug 3, 2017 at 19:47

1 Answer 1

7

I note the following boldfaced (my boldface) sentence in the git apply documentation:

Reads the supplied diff output (i.e. "a patch") and applies it to files. When running from a subdirectory in a repository, patched paths outside the directory are ignored. With the --index option ...

It seems in this case that git patch is deciding that the files are outside the directory. If run from the top level, it should stop deciding that (though of course $PWD itself will change too; any --directory option, if one is required, would need a different argument).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.