git apply :错误尾随空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15732528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:23:48  来源:igfitidea点击:

git apply : error trailing whitespace

gitpatch

提问by ben S

Lately, I've been playing a little bit with git. I'm trying to simulate to apply a patch to my master branch, this patch comprehends a commit where I added some comments to a java operation. I generated the patch using git format-patch. Then I switched to my master branch to apply the patch. the following errors occurred when executing the git apply command :

最近,我一直在玩 git。我试图模拟将补丁应用到我的主分支,这个补丁包含一个提交,我在其中向 Java 操作添加了一些注释。我使用 git 生成了补丁format-patch。然后我切换到我的主分支来应用补丁。执行 git apply 命令时出现以下错误:

path/to/my/patch/file: line x
path/to/my/patch/file: line x+1
path/to/my/patch/file: line x+2
path/to/my/patch/file: line x+3

I note that I also tried the following arguments : --ignore-space, ignore-whitespace,

我注意到我还尝试了以下参数:--ignore-space, ignore-whitespace,

回答by Derek Ekins

If you are not concerned with applying trailing whitespaces to your repo you can use the flag --whitespace=fixto ignore the error and apply anyway

如果您不关心将尾随空格应用于您的存储库,您可以使用该标志--whitespace=fix来忽略错误并无论如何应用

git apply --whitespace=fix your.patch

I have heard some people say that the default is to warn and apply the patch, but that has not been my experience and the above solution seems to do what I want.

我听说有人说默认是警告并应用补丁,但这不是我的经验,上面的解决方案似乎可以满足我的需求。