git apply is making no changes to files

2019-03-31 06:20发布

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?

标签: git patch
1条回答
等我变得足够好
2楼-- · 2019-03-31 06:49

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).

查看更多
登录 后发表回答